Directives

Top  Previous  Next

Directives provide means to control compiler behavior.

·Conditional compilation : $IFDEF, $IF, $ELSE, etc.
·Code Inclusions : $I, $INCLUDE_ONCE, $FILTER, etc.
·Errors and messages : $

 

Conditional Defines

·{$DEFINE NAME_TOKEN} : define NAME_TOKEN conditional
·{$UNDEF NAME_TOKEN} : un-defines NAME_TOKEN conditional

Conditional Compilation

·{$IFDEF NAME_TOKEN}
·{$IFNDEF NAME_TOKEN}
·{$IF expression}
·{$ELSE}
·{$ENDIF}

Conditional expressions

$IF allows to specify a Boolean expression to control conditional compilation, that expression can use any constant defined previously, as well as any stateless built-in function.

It can also invoke the following special functions:

·Defined(nameToken : String) : returns true if the token is defined when the compilation reaches the expression.
·Declared(symbolName : String) : returns true if there is a symbol name in scope when compilation reaches the expression.

Note that the above special functions can also be used in regular code, but then, they'll be evaluated at runtime, when compilation has been completed.

Detecting DWSCRIPT and version

The DWSCRIPT conditional is set by default and can be used to help make code compile across different Pascal compiler.

 

The CompilerVersion constant is also defined, it's a numeric floating-point value, at the format YYYYMMDD.SUB, so compiler version 20130524.0 corresponds to the main version of 24 may 2013.

Source Code Inclusions

·{$I 'filename'} : includes the specified file "verbatim" in the source.
·{$INCLUDE 'filename'} : includes the specified file "verbatim" in the source.
·{$INCLUDE_ONCE 'filename'} : includes the specified "verbatim" in the source only if it hasn't already been included (directly or through inclusion).
·{$F 'filename'} : includes the specified file in the source after applying the filter on it.
·{$FILTER 'filename'} : includes the specified file in the source after applying the filter on it.

Special Inclusions

You can use them with either $I or $INCLUDE, they include a string literal with the relevant information.

·{$I %FUNCTION%} : includes a string literal containing the name of the function or method where the directive is.
·{$I %FILE%} : includes a string literal containing the current file name where the directive is.
·{$I %LINE%} : includes a string literal containing the line number where the directive is.
·{$I %DATE%} : includes a string literal containing the date of compilation (yyyy-mm-dd).
·{$I %TIME%} : includes a string literal containing the time of compilation (hh:nn:ss).

 

Message control

·{$WARNINGS ON|OFF} : enable or disable compiler warnings.
·{$HINTS ON|OFF|NORMAL|STRICT|PEDANTIC} : controls compiler hints.
oON : enables hints, at the level defined in the Config.HintsLevel
oOFF : disables hints
oNORMAL : enables hints at the normal level
oSTRICT : enables hints at the strict level
oPEDANTIC : enables hints at the pedantic level

Message command

·{$HINT 'message'} : emits message as a hint.
·{$WARNING 'message'} : emits message as a warning.
·{$ERROR 'message'} : emits message as an error (prevents execution).
·{$FATAL 'message'} : emits message as a fatal error (aborts compilation).