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
$Define Defines a compiler directive symbol - as used by IfDef
$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
$IfOpt Tests for the state of a Compiler directive
$UnDef Undefines a compiler directive symbol - as used by IfDef
 Author links

 Buy Website Traffic at
 Buywebsitetrafficexperts.com

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




 
Example code : Setting up and using a user defined symbol
// 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
  // 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;
 
end.
Hide full unit code
   We are in danger mode!
 
Delphi Programming Neil Moffatt 2002 - 2017. All rights reserved.  |  Home Page