I have the following code sprinkled throughout my project. The purpose is to print information only when either the project is in debug build OR a variable Debug = True. That was all good until I decided that I wanted to control the App.Debug var which was a constant.
#If DebugBuild Or App.Debug = True Then
Print "TRACE "+ CurrentMethodName + " Start"
#EndIf
Once I change debug to a property it will no longer compile since anything in the Compiler Directive (#If) MUST be a constant.
So I can either replace the code
#If DebugBuild Or App.Debug = True Then
#Endif
to simply:
If App.debug = True Then
Is there another way to do this without loosing the compiler directive??? So far, I have not found a good way…
You must use constants with compiler directives because the calculation is performed once at compile time. A property or variable is evaluated at runtime and thus cannot control what the compiler builds.
You must either use a constant, or a runtime evaluation as you had discovered.