Delphi Programming

FreePascal detection and versioning

2,919pages on
this wiki
Add New Page
Talk0 Share

Free Pascal defines a lot of conditionals, both for platform as for target support. The most important one is the FPC conditional

  {$ifdef FPC}    
    // put your FPC code here  
    // assume Delphi or TP here. 

Besides this, there is the matter of target (architecture and OS) support:

  • a conditional per architecture (CPU family) are
  {$ifdef i386}   
    // 32-bit PC code here.  
  {$ifdef cpux86_64} 
    // aka AMD64.   
    // 64-bit PC code here.  
  {$ifdef powerpc}   
    // 32-bit powerpc specific code here  
  {$ifdef powerpc64}   
    // 64-bit powerpc specific code here  
  {$ifdef m68k}      
    // m68k, Motorola 68010+ is not supported in 2.0+ at the moment, but might be resurrected.  
  {$ifdef Sparc}     
    // 32-bit Sparc support  
  {$ifdef Sparc64}     
    // 64-bit Sparc support is partially done, but not releaseworthy yet.  
  {$ifdef Arm}     
    // 32-bit ARM support.  
  // Comment from dkropf
  // {$ifdef i386} DOES NOT WORK! use 
  {$ifdef cpui386}
  • General conditions for wordsizes and endianness
  {$ifdef CPU32}
      SizeofPointe=32;   // 32-bit = 32
  {$ifdef CPU64}
      SizeofPointe=64;   // 64-bit = 64
  {$ifdef ENDIAN_BIG}
    I:=a and 255 + (b and 255) shl 16;
  {$ifdef ENDIAN_LITTLE}
    I:=b and 255 + (a and 255) shl 16; 
  • test for families of OSes.
{$ifdef MSWindows}
     // ce + win32 + win64, delphi compat
  {$ifdef Windows}
     // ce + win32 + win64, more logical.
  {$ifdef Unix}
     // all Unix like OSes. Linux/*BSD/OS X and Solaris. BeOS too if it ever released again.
  {$ifdef BSD}
     // Free/Net/OpenBSD and Mac OS X 
  • Specific OSes
{$ifdef win32} 
    //  95/98/ME and 32-bit NT/2k/XP/Vista
  {$ifdef win64} 
    //  64-bit/XP/Vista
  {$ifdef wince}
    // Windows CE family including PocketPC 2003 and Windows Mobile 5
  {$ifdef Linux}
    // linux}
  {$ifdef FreeBSD}
    // FreeBSD
  {$ifdef Darwin}
    // Darwin is the base OS name of Mac OS X, like NT is the name of the Win2k/XP/Vista kernel. Mac OS X = Darwin + GUI.
  {$ifdef SunOS}
    // similarly with Solaris. Ifdef solaris also works though.
  // additionally OS2 , netware, netwlibc (Linux based Novell), BeOS, AmigaOS.
{$ifdef ver2}
     // all versions 2.x
  {$ifdef ver2_2}
    // all versions 2.2
   // or (delphi/FPC2+ style): 
  {$if (fpc_version=2) and (fpc_release>0) or ((fpc_release=0) and (fpc_patch>3))}  
    {$info At least this is version 2.0.4}  
    {$fatal Problem with version check}  
  • dialects
{$ifdef fpc} // only warn when
   {$ifndef fpc_delphi} // fpc is not in delphi mode
     {$info please compile this unit with -Sd to enable delphi mode.}
  • Since FPC 2.2.4, a directive FPC_FULLVERSION supports numeric comparison like this
 {$if FPC_FULlVERSION> 20204} 
   // means greater than 2.2.4 here

Ad blocker interference detected!

Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

Also on Fandom

Random Wiki