{$define Symbol}
|
From this point on in your code, the compiler knows the symbol Symbol. Symbols are, like the Pascal language, case insensitive.
You can also de ne a symbol on the command line. the -dSymbol option de nes the symbol Symbol. You can specify as many symbols on the command line as you want.
Unde ning an existing symbol is done in a similar way:
{$undef Symbol}
|
If the symbol didn't exist yet, this doesn't do anything. If the symbol existed previously, the symbol will be erased, and will not be recognized any more in the code following the {$undef ...} statement.
You can also unde ne symbols from the command line with the -u command-line switch.
To compile code conditionally, depending on whether a symbol is de ned or not, you can enclose the code in a {$ifdef Symbol} ...{$endif} pair. For instance the following code will never be compiled:
{$undef MySymbol}
{$ifdef Mysymbol} DoSomething; ... {$endif} |
Similarly, you can enclose your code in a {$ifndef Symbol} ...{$endif} pair. Then the code between the pair will only be compiled when the used symbol doesn't exist. For example, in the following example, the call to the DoSomething will always be compiled:
{$undef MySymbol}
{$ifndef Mysymbol} DoSomething; ... {$endif} |
You can combine the two alternatives in one structure, namely as follows
{$ifdef Mysymbol}
DoSomething; {$else} DoSomethingElse {$endif} |
In this example, if MySymbol exists, then the call to DoSomething will be compiled. If it doesn't exist, the call to DoSomethingElse is compiled.