scope of defines are per unit (or the main program).Damn!
Yes, i know i can set defines in Project-Properties, but i'd like to avoid that, because it's a dynamic functionality:If you use Lazarus IDE, you can use Build Modes for different defines.
Use a Unit --> Inherit the Define --> Functionality becomes available
Opinion?A weird strategy IMO. However I don't know details of your use case.
Just declaring a regular Const at the Top of the Unit, and then in my other units just encase the whole Function-Body in a
"If MyConst Then Begin ..... End" as first/last line of code inside the functions.
I don't think that will work, since the const will fail to compile if it hasn't been declared yet.Damn! didn't think of that.
Delphi has {$IF (NOT) DECLARED(...)} that would be suitable for this task, but I don't know if FreePascal has that (I can't find it documented anywhere, only {$IF (NOT) DEFINED(...)}).
DECLARED(passym)Will try that one!
Evaluates to TRUE if the pascal symbol is declared at this point in the sources, or FALSE if it is not yet defined.
Delphi has {$IF (NOT) DECLARED(...)} that would be suitable for this task, but I don't know if FreePascal has that (I can't find it documented anywhere, only {$IF (NOT) DEFINED(...)}).
Bingo!
https://www.freepascal.org/docs-html/prog/progsu127.html#x140-1410002.4.1QuoteDECLARED(passym)Will try that one!
Evaluates to TRUE if the pascal symbol is declared at this point in the sources, or FALSE if it is not yet defined.
Please note that it currently does not work with namespaced units. So if you have e.g. a unit UUnit.Test then using DECLARED(UUnit.Test) fails to compile. Even if you use the default namespace option -FNuunit, only use Test in the program and DECLARED(Test) for your include it will evaluate to False.
With non-namespaced units it will work however.