Configure Menu | Advanced
The Conditional Defines menu items is an advanced feature allowing for a convenient way to include or exclude sections of a program during the compilation process.
A common use of this feature might to include or exclude debugging statements and mechanisms. Conditional Defines are a property of a project. A saved project will retain the Conditional Define settings when the project is saved and restore them
when the project is loaded again.
When the Conditional Defines menu item is selected a Conditional Defines dialog is presented:
The "Add" button presents a Conditional Define Property Editor:
The Description field represents the Conditional Define in the Conditional Defines Dialog list. The description is free to have spaces. The Declaration field contains a text programming statement that will be compiled before any other part of the program.
Conditional compiler directives can then reference the declared symbol to include or exclude program lines. For example consider that debugging statements are needed to track down a problem in text programming. The above Conditional Define looks like this after the
"Ok" button is clicked:
If the checkbox is checked then the associated declaration is included in the compilation. Text programs can then reference DebugActive like this:
If the checkbox is unchecked then this Conditional Define declaration is not present in the compilation. The conditional program lines will not be included. The lines can be left in the program without any detrimental effect waiting for some time in the future when the
diagnostics are re-instated by again checking the Conditional Define. Note that because the conditional is {$IFDEF} - If Defined - the conditional is checking if the symbol itself is defined. No question is being asked of the value in this case.
It is possible to perform conditional compilation based on the value of an expression if that expression can be determined at compile-time by using the $IF construction. Consider a project that uses an include file. The include file as well as the project will undergo revisions.
To make sure that the include file being referenced is the correct version for the project a conditional like this could be used (assuming that the include file had an ordinal constant named IncludeFileVersion):
What is conditionally included is an interntional mistake which stops compilation and indicates indirectly the nature of the problem:
Value based comparisons are more restricted than general language syntax. Expressions must be ordinal variables or ordinal literals and there must be a space between each part of the expression.
As conditional compilation is an advanced feature it is incumbant on the user to provide a declaration that is accurate. If the declaration provided cannot be compiled this message will appear: