| Description |
The $IfOpt compiler directive is a meta-directive - it tests for the + or - state of a single character compiler directive.
For example:
{$IfOpt H+}
ShowMessage('Longstrings are set on');
{$EndIf}
It is useful to report on directive settings at the start of a program, when testing.
|
|
| Notes |
$IfOpt can be used multiple times in your code.
|
|
| 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 |
| $UnDef |
|
Undefines a compiler directive symbol - as used by IfDef |
|
|
|
| Example code : Show various default directive settings |
// 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); begin // Show the default settings of various compiler directives
{$IfOpt A+}
ShowMessage('Align is On');
{$Else}
ShowMessage('Align is Off');
{$EndIf}
{$IfOpt B+}
ShowMessage('BoolEval is On');
{$Else}
ShowMessage('BoolEval is Off');
{$EndIf}
{$IfOpt H+}
ShowMessage('LongStrings is On');
{$Else}
ShowMessage('LongStrings is Off');
{$EndIf}
end; end.
|
| Hide full unit code |
Align is Off
BoolEval is Off
LongStrings is On
|
|