DelphiBasics
$IfOpt
Compiler Directive
Tests for the state of a Compiler directive
{$IfOpt Switch-}
  ...
 {$Else}
  ...
 {$EndIf}
1
2 {$IfOpt Switch+}
  ...
 {$Else}
  ...
 {$EndIf}
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
$DefineDefines a compiler directive symbol - as used by IfDef
$ElseStarts the alternate section of an IfDef or IfNDef
$EndIfTerminates conditional code compilation
$IfDefExecutes code if a conditional symbol has been defined
$IfNDefExecutes code if a conditional symbol has not been defined
$UnDefUndefines a compiler directive symbol - as used by IfDef
 Download this web site as a Windows program.




 
Example code : Show various default directive settings
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;
Show full unit code
  Align is Off
  BoolEval is Off
  LongStrings is On
 
Delphi Programming © Neil Moffatt . All rights reserved.  |  Home Page