Chapter 8. Compiler Directives

Compiler directives are special comments that control the compiler and its behavior, similar to #pragma directives in C++. This chapter discusses compiler directives and lists all the compiler directives Delphi supports.

A directive comment is one whose first character is a dollar sign ($). You can use either kind of Pascal-style comment:

{$AppType GUI}
(*$AppType GUI*)

You cannot use a C++ style comment (//$Apptype) for a compiler directive.

If the first character of a comment is not a dollar sign, the comment is not a compiler directive. A common trick to deactivate or “comment out” a compiler directive is to insert a space or other character just before the dollar sign, for example:

{ $AppType GUI}
(**$AppType GUI*)

Delphi has three varieties of compiler directives: switches, parameters, and conditional compilation. A switch is a Boolean flag: a feature can be enabled or disabled. A parameter provides information, such as a filename or stack size. Conditional compilation lets you define conditions and selectively compile parts of a source file depending on which conditions are set. Conditions are Boolean (set or not set).

The names and parameters of compiler directives are not case-sensitive. You cannot abbreviate the name of a compiler directive. Delphi ignores extra text in the comment after the compiler directive and its parameters (if any). You should refrain from including extra text, though, because future versions of Delphi might introduce additional ...

Get Delphi in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.