DelphiBasics
$Define
Compiler Directive
Defines a compiler directive symbol - as used by IfDef
  {$Define Symbol}
Description
The $Define compiler directive defines a Symbol. By doing so, the symbol is now On.
 
When a symbol is on, $IfDef will compile conditional code, and $IfNDef will not.
 
When a symbol is off, $IfNDef will compile conditional code, and $IfDef will not.
 
Delphi provides some predefined symbols, such as Console that is on for a console application and off for a GUI application.
 
$Define is very useful when developing code, allowing various sections to be compiled when testing.
Related commands
$Else Starts the alternate section of an IfDef or IfNDef
$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
$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 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}

  text := 'We are out of test mode';

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