I just want to confirm that this is a true statement
If in a global module I define a BOOLEAN Constant of “MYTEST” and set that value to FALSE
Then I enclose code between #IF MYTEST … #ENDIF , then that code would NOT be compiled into the end product
If so, can I define an INTEGER constant? MYTEST = 3 , #IF MYTEST=3 … #ENDIF? or #IF MYTEST>1
I need to create a single code base, that not only will have #IF TARGETxxx but also 3 actual “versions”, where each “version” will need to have some code included, but not other.
Dave, I have tried it before with Boolean constants and it works. I have not tried it with an Integer constant, I thought it had to be Boolean, but I could be wrong.
The expression has to be a boolean expression made up of constant values and comparisons IF I recall correctly
So it has to be composed of literals, constants and evaluate to TRUE or FALSE
EDIT : place this in the open event of a windows in a new desktop app and play around with it
Const foo = 1
Const s = "s"
#If (foo = 1) and (s="s") Then
MsgBox "foo = 1"
#EndIf
[quote=327629:@Norman Palardy]The expression has to be a boolean expression made up of constant values and comparisons IF I recall correctly
So it has to be composed of literals, constants and evaluate to TRUE or FALSE[/quote]
You just beat me to it… But that as not ALWAYS true… I remember a time before expressions were allowed… maybe that was what Merv was remembering
Expressions have been allowed since day 1 BUT you can not use properties or other variables, language function calls etc
EVERYTHING has to be basically a constant or literal or something that can be evaluated at compile time which is why no Xojo language functions can be used - the compiler does not RUN the code
Thanks…
I need to refactor a few things in hopes of minimizing the number of times I need to refer to the constants…
What I am trying to do is make an AppleStore version, and a version I can sell outside … The outside version will require registration and other functions that are not needed/allowed in the AppleStore version, but I one only ONE project file, where I can change a constant from TRUE to FALSE and recompile
You can do it with 3 global constants. One would be cleaner if it were possible, but setting one of them to TRUE and the other two to FALSE, is trivial.
I’m pretty sure you are mistaken on that. I remember the use of expressions being a new feature in some version…
To check I pulled out my old RB V3 CD from 2001 to check the docs there… The Entry for #If :
[code]#If …#Else…#Endif Statement
Used to control conditional compilation.
Syntax #If TargetBoolean Then
//OS specific code #Else
//Other OS-specific code #Endif
Part Type
TargetBoolean Boolean Constant
Description
TargetMacOS, TargetPPC, Target68K, TargetCarbon, TargetWin32, or DebugBuild constant, used to determine the operating system that will include the code the follows.
???
Notes
Use conditional compilation to isolate platform-specific statements such as toolbox calls or AppleEvent routines. The code following the #If statement is included only in the build for that operating system. Target68K, TargetPPC, and TargetCarbon are mutually exclusive subsets of TargetMacOS.
[/code]
Also under RBVersion there is no mention of of using it in conditional compilation
no
there no place to put things “around” methods , modules, windows etc
you’d need to do
#if booleanValue
Window foo
end window
#endif
#if booleanValue
Sub foo()
end sub
#endif
and there’s no way to do that
so you use other means to achieve this
methods
use one as the API and inside use #if etc to call the one you really want
however unused methods will not be stripped - unless they are in a module that is unused and the entire module gets stripped
modules
unused modules get stripped - so if you #if etc NEVER call methods in that module it will be stripped
windows are similar in that if they are NOT used they will be stripped
Thanks Norman…
So if for example… Module ABC has 3 methods and each method started and ended with #IF/#ENDIF that resolved to FALSE then the compiled code would have no reference to Module ABC? If so, that is good enough for what I’m seeking
And if one of the Methods called Window XYZ, then it do would be excluded?