DelphiBasics
$EndIf
Compiler Directive
Terminates conditional code compilation
{$IfDef Symbol}
 ... Code to run when the symbol is defined ...
 {$Else}
 ... Code to run when the symbol is not defined ...
 {$EndIf}
Description
The $EndIf compiler directive terminates a section of conditionally compiled code.
 
See $IfDef and $IfNDef for useage.
Related commands
$DefineDefines a compiler directive symbol - as used by IfDef
$ElseStarts the alternate section of an IfDef or IfNDef
$IfDefExecutes code if a conditional symbol has been defined
$IfNDefExecutes code if a conditional symbol has not been defined
$IfOptTests for the state of a Compiler directive
$UnDefUndefines a compiler directive symbol - as used by IfDef
 Download this web site as a Windows program.




 
Example code : Setting up and using a test mode symbol
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}

  // Display the value of text if we are in test mode
  {$IfDef TESTMODE}
  ShowMessage('text = '+text);
  {$Else}
  ShowMessage('Out of test mode now');
  {$EndIf}
end;
Show full unit code
  We are in test mode
  Out of test mode now
 
Delphi Programming © Neil Moffatt . All rights reserved.  |  Home Page