Forcing use of the IDE

Post

Posted
Rating:
#1 (In Topic #955)
Avatar
Regular
thatbruce is in the usergroup ‘Regular’
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, <COLOR color="#BF40BF">brilliant</COLOR>.

b

Online now: No Back to the top

Post

Posted
Rating:
#2
Guru
BruceSteers is in the usergroup ‘Guru’
I stumbled upon this page one day…
/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.
Online now: No Back to the top

Post

Posted
Rating:
#3
Guru
BruceSteers is in the usergroup ‘Guru’
 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
Online now: No Back to the top

Post

Posted
Rating:
#4
Avatar
Regular
thatbruce is in the usergroup ‘Regular’
Someone has "cleaned up" that page. IIRC the referred to "discussion" was somewhat heated.  :D

Online now: No Back to the top

Post

Posted
Rating:
#5
Avatar
Regular
thatbruce is in the usergroup ‘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.

Online now: No Back to the top
1 guest and 0 members have just viewed this.