Delphi compiler directivesSee alsoEach Delphi compiler directive is classified as either a switch, parameter, or conditional compilation directive. Choose a directive from the list of compiler directives for detailed information.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. See Conditional compilation for more information.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, DCC32.EXE and the IDE, Delphi32.exe. The Project|Options|Compiler 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, DCC32 -$R+ MYPROGYou can also place directives in a configuration file. Compiler directives in the source code always override the command-line compiler directives and the IDE project options.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.
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. See Conditional compilation for more information.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, DCC32.EXE and the IDE, Delphi32.exe. The Project|Options|Compiler 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, DCC32 -$R+ MYPROGYou can also place directives in a configuration file. Compiler directives in the source code always override the command-line compiler directives and the IDE project options.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.
给一个编译EXE和一个编译DLL的例子看看!
一般在WINDOWS下虚拟DOS用默认设置,没有问题:E:\Program Files\Borland\Delphi7\Demos\Ado\AdoTest>dcc32 adotest
Borland Delphi Version 15.0
Copyright (c) 1983,2002 Borland Software Corporation
RecError.pas(365)
AdoMain.pas(2484)
ADOTEST.DPR(14)
2866 lines, 0.98 seconds, 1076372 bytes code, 16321 bytes data.E:\Program Files\Borland\Delphi7\Demos\Ado\AdoTest>以下是DLL的例子
E:\Program Files\Borland\Delphi7\Projects>dcc32 dlltest
Borland Delphi Version 15.0
Copyright (c) 1983,2002 Borland Software Corporation
Dlltest.dpr(26)
27 lines, 0.22 seconds, 69616 bytes code, 3589 bytes data.E:\Program Files\Borland\Delphi7\Projects>都可以编译!