Sign in Join
Wiki copytemporary

Revision 2 of 2, by Kai Burghardt on 8-6-2022. The page as it is now.

$IF

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

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

Also, enable you to write complex conditions that you cannot do with the {$ifdef …},

And there are two bool functions[defined/undefined] that can be mixedup with [and/or] logic operators, For example:

pascal
//Befor you need write these conditions to check some conditions:
{$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 readabl 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}

From the Free Pascal wiki, page "$IF", as it stood on 2022-08-06 after a change by Kai Burghardt, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.