Compiler Directive
Tests for the state of a Compiler directive
1   {$IfOpt Switch-}
2   {$IfOpt Switch+}
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');

It is useful to report on directive settings at the start of a program, when testing.
$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
 Author links

 Buy Website Traffic at

 Buy Proxies at
 Download this web site as a Windows program.

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;
  Forms, Dialogs;
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
Form1: TForm1;
{$R *.dfm} // Include form definitions
procedure TForm1.FormCreate(Sender: TObject);

  // Show the default settings of various compiler directives
  {$IfOpt A+}
    ShowMessage('Align is On');
    ShowMessage('Align is Off');

  {$IfOpt B+}
    ShowMessage('BoolEval is On');
    ShowMessage('BoolEval is Off');

  {$IfOpt H+}
    ShowMessage('LongStrings is On');
    ShowMessage('LongStrings is Off');
Hide full unit code
   Align is Off
   BoolEval is Off
   LongStrings is On
Delphi Programming Neil Moffatt 2002 - 2018. All rights reserved.  |  Home Page