Forcing use of the IDE
Posted
#1
(In Topic #955)
Regular

Sometimes one can over-think things and go looking for an intergalactic laser driven solution when a simple screwdriver is just as good, if not better.
I was looking for a way to temporarily "disable" a project so it could only be run from inside the IDE. Why? Because I have just spent a day inserting debugging code in it and wanted to stop myself and colleagues running the last compiled version.
The salubrious Mr Bruce Steers came up with the simple solution.
Try this in your startup class
#If Exec
Quit
#Endif
When compiling an exe gambas sets the x flag. The IDE does not when debugging.
Brilliant! If not, well, <COLOR color="#BF40BF">brilliant</COLOR>.
b
Posted
Guru

/lang/.if - Gambas Documentation
Quite handy finding the Exec bit for the very same reason you needed it but #If also has a few other handy uses <EMOJI seq="1f60a" tseq="1f60a">😊</EMOJI>
And to clarify for all how the above fix works…
When the compiler creates an executable it uses the gbc3 -x option.
The IDE does not, thus making the preprocessor Exec state true for an executable but not while debugging in the IDE.
If you compile an exe yourself outside the IDE using gbc3 and gba3 then be sure to use the -x flag with gbc3.
Posted
Guru

So to do it the other way round you cannot do this…
#If Not Exec
Quit
#Endif
But you can do this…
#If Exec
#Else
Quit
#Endif
Posted
Regular

Posted
Regular

BruceSteers said
One other thing. You cannot use Not with #If
So to do it the other way round you cannot do this…
#If Not Exec
Quit
#Endif
But you can do this…
#If Exec
#Else
Quit
#Endif
But actually, in fact, I believe and have tested, you can use #If Not (Exec) !
In other words force the #If to use a function rather than a straight value.
1 guest and 0 members have just viewed this.


