DelphiBasics
$Else
Compiler Directive
Starts the alternate section of an IfDef or IfNDef
{$IfDef Symbol}
 ... Code to run when the symbol is defined ...
 {$Else}
 ... Code to run when the symbol is not defined ...
 {$EndIf}
Description
The $Else compiler directive starts the alternate section of an IfDef or IfNDef conditional compilation statement.
 
The code it starts is compiled if the conditional statement returns false.
Related commands
$DefineDefines a compiler directive symbol - as used by IfDef
$EndIfTerminates conditional code compilation
$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 user defined symbol
begin
  // Set our code into dangerous mode
  {$Define DANGERMODE}

  // Are we out of danger?
  {$IfNDef DANGERMODE}
  ShowMessage('We are out danger at present');
  {$Else}
  ShowMessage('We are in danger mode!');
  {$EndIf}

  // Switch off danger mode
  {$UnDef DANGERMODE}
end;
Show full unit code
  We are in danger mode!
 
Delphi Programming © Neil Moffatt . All rights reserved.  |  Home Page