Page 1 of 1

Forcing use of the IDE

Posted: Sunday 11th December 2022 12:07pm
by thatbruce
This one is just too good not to share.
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, brilliant.

b

Re: Forcing use of the IDE

Posted: Monday 12th December 2022 8:04pm
by BruceSteers
I stumbled upon this page one day...
http://gambaswiki.org/wiki/lang/.if

Quite handy finding the Exec bit for the very same reason you needed it but #If also has a few other handy uses 😊

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.

Re: Forcing use of the IDE

Posted: Monday 12th December 2022 8:44pm
by BruceSteers
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

Re: Forcing use of the IDE

Posted: Tuesday 13th December 2022 8:46am
by thatbruce
Someone has "cleaned up" that page. IIRC the referred to "discussion" was somewhat heated. :D

Re: Forcing use of the IDE

Posted: Tuesday 13th December 2022 8:51am
by thatbruce
BruceSteers wrote: ↑Monday 12th December 2022 8:44pm 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.