| Description |
The $UnDef compiler directive removes a Symbol definition. By doing so, the symbol is now Off.
When a symbol is on, $IfDef will compile conditional code, and $IfNDef will not.
When a symbol is off, $IfNDef will compile conditional code, and $IfDef will not.
Delphi provides some predefined symbols, such as Console that is on for a console application and off for a GUI application.
|
|
| Related commands |
| $Define |
|
Defines a compiler directive symbol - as used by IfDef |
| $Else |
|
Starts the alternate section of an IfDef or IfNDef |
| $EndIf |
|
Terminates conditional code compilation |
| $IfDef |
|
Executes code if a conditional symbol has been defined |
| $IfNDef |
|
Executes code if a conditional symbol has not been defined |
| $IfOpt |
|
Tests for the state of a Compiler directive |
|
|
|
|
| Example code : Setting up and using a test mode symbol |
// Full Unit code. // ----------------------------------------------------------- // You must store this code in a unit called Unit1 with a form // called Form1 that has an OnCreate event called FormCreate. unit Unit1; interface uses Forms, Dialogs; type TForm1 = class(TForm) procedure FormCreate(Sender: TObject); end; var Form1: TForm1; implementation {$R *.dfm} // Include form definitions procedure TForm1.FormCreate(Sender: TObject); var
text : string;
begin // Set our code into test mode
{$Define TESTMODE}
text := 'We are in test mode';
// Display the value of text if we are in test mode
{$IfDef TESTMODE}
ShowMessage('text = '+text);
{$EndIf}
// Switch off test mode
{$UnDef TESTMODE}
text := 'We are out of test mode';
// Display the value of text if we are in test mode
{$IfDef TESTMODE}
ShowMessage('text = '+text);
{$EndIf}
end; end.
|
| Hide full unit code |
text = We are in test mode
|
|