Forcing use of the IDE

Post your Gambas programming questions here.
Post Reply
User avatar
thatbruce
Posts: 161
Joined: Saturday 4th September 2021 11:29pm

Forcing use of the IDE

Post 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
Have you ever noticed that software is never advertised using the adjective "spreadable".
User avatar
BruceSteers
Posts: 1521
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Forcing use of the IDE

Post 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.
If at first you don't succeed , try doing something differently.
BruceS
User avatar
BruceSteers
Posts: 1521
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Forcing use of the IDE

Post 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
If at first you don't succeed , try doing something differently.
BruceS
User avatar
thatbruce
Posts: 161
Joined: Saturday 4th September 2021 11:29pm

Re: Forcing use of the IDE

Post by thatbruce »

Someone has "cleaned up" that page. IIRC the referred to "discussion" was somewhat heated. :D
Have you ever noticed that software is never advertised using the adjective "spreadable".
User avatar
thatbruce
Posts: 161
Joined: Saturday 4th September 2021 11:29pm

Re: Forcing use of the IDE

Post 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.
Have you ever noticed that software is never advertised using the adjective "spreadable".
Post Reply