$IF

The {$if …} directive can be used in conditional compilation.

// pointermath directive did not exist prior FPC 3.0.0
{$if FPC_VERSION > 2}
    // pointer arithmetics is bad. very bad
    {$pointermath off}
{$endif}

This directive enables the use of complex conditions that are not possible with {$ifdef}.

It also introduces boolean functions such as `defined()` and `undefined()`, which can be combined with logical operators like `and` and `or`. This makes condition checks simpler and more readable. For example:

// Previously, to check multiple conditions, you had to write:
{$define SOMETHING}
{$define SOMETHINGELSE}
{$ifdef SOMETHING}//Union $IfDef to check multiple conditions
    {$ifdef SOMETHINGELSE}
   {$ModeSwitch advancedrecords}
  {$endif}
{$endif}

//But with the {$IF} you can check conditions together:
{$if defined(SOMETHING) and defined(SOMETHINGELSE)}//simple and readable instead of union {$IFDef}`s
  {$ModeSwitch advancedrecords}
{$endif} 

{$if defined(somthing) or defined(somethingelse)}
  //Whatever you need!
{$endif}

{$if undefined(what) and defined(somethingelse)}
  //Just for note, Another usage!
{$endif}

And there is another example.

{$IF DEFINED(XXX)}  
  // XXX Code here  
{$ELSEIF DEFINED(YYY)}  
  // YYY code here  
{$ELSEIF DEFINED(ZZZ)}  
  // ZZZ code here  
{$ELSE}  
  // And default code here  
{$ENDIF}

Example for selecting between OSes:

  {$if defined (windows)}a :=5;
  {$elseif defined(linux)}a :=6;
  {$elseif defined(darwin)}a :=7;
  {$else}a :=8;{$endif}
Directives, definitions and conditionals definitions
global compiler directives • local compiler directives Conditional Compiler Options • Conditional compilation • Macros and Conditionals • Platform defines $IF