RAD Studio (Common)
ContentsIndex
PreviousUpNext
Delphi compiler directives

Each Delphi compiler directive is classified as either a switch, parameter, or conditional compilation directive.  

A compiler directive is a comment with a special syntax. Compiler directives can be placed wherever comments are allowed. A compiler directive starts with a $ as the first character after the opening comment delimiter, immediately followed by a name (one or more letters) that designates the particular directive. You can include comments after the directive and any necessary parameters. 

Three types of directives are described in the following topics:

  • Switch directives turn particular compiler features on or off. For the single-letter versions, you add either + or - immediately after the directive letter. For the long version, you supply the word "on" or "off."
* Switch directives are either global or local.
  • Global directives affect the entire compilation and must appear before the declaration part of the program or the unit being compiled.
  • Local directives affect only the part of the compilation that extends from the directive until the next occurrence of the same directive. They can appear anywhere.
Switch directives can be grouped in a single compiler directive comment by separating them with commas with no intervening spaces. For example:

   {$B+,R-,S-}

  • Parameter directives. These directives specify parameters that affect the compilation, such as file names and memory sizes.
  • Conditional directives. These directives cause sections of code to be compiled or suppressed based on specified conditions, such as user-defined conditional symbols.
All directives, except switch directives, must have at least one space between the directive name and the parameters. Here are some examples of compiler directives:

{$B+}
    {$STACKCHECKS ON}
    {$R- Turn off range checking}
    {$I TYPES.INC}
    {$M 32768,4096}
    {$DEFINE Debug}
    {$IFDEF Debug}
    {$ENDIF}

You can insert compiler directives directly into your source code. You can also change the default directives for the command-line compiler, dccil and the IDE, bds.exe.  

The Project|Options dialog box contains many of the compiler directives; any changes you make to the settings there will affect all units whenever their source code is recompiled in subsequent compilations of that project. If you change a compiler switch and compile, none of your units will reflect the change; but if you Build All, all units for which you have source code will be recompiled with the new settings. 

When using the command-line compiler, you can specify compiler directives on the command line; for example,

DCCIL -$R+ MYPROG

If you are working in the Code editor and want a quick way to see what compiler directives are in effect, press Ctrl+O O. You will see the current settings in the edit window at the top of your file.

List of Compiler Directives 

Conditional Compilation

Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!