2

I've seen conditional compile directives with expressions related to the version of the compile, but I'm unable to locate them again.

How would I correctly write this in Free Pascal?

program do_stuff;
begin
{$IF VER > 2.4}
// Some code here
{$ENDIF}
end.

Thanks.

Gustavo Carreno
  • 9,499
  • 13
  • 45
  • 76

2 Answers2

2
{$IF FPC_FULLVERSION>=20400} 
  // code here
{$ENDIF}

Available only after 2.2.4, see here. Requires macro support, see here.

Sertac Akyuz
  • 54,131
  • 4
  • 102
  • 169
  • This answer also has merit, but it's not compatible with earlier versions, right? Or am I wrong somehow? Cheers. – Gustavo Carreno Jan 22 '11 at 13:07
  • @Gustavo - Yes, I'd think it has its merits, since it exactly answers the question. But incompatibility with earlier versions might be important, that's why I pointed it out. – Sertac Akyuz Jan 22 '11 at 15:09
  • 1
    Since FPC is free, old versions die out much quicker than e.g. Delphi. The pre 2.2.4 is usage already very, very low, and will probably decimate again in the coming year, with lazarus finally upgrading to the 2.4 branch – Marco van de Voort Jan 22 '11 at 22:20
1

This is a copy and paste from Free Pascal Website:

{$IF (FPC_VERSION > 2) or  
     ((FPC_VERSION = 2)  
       and ((FPC_RELEASE > 0) or  
            ((FPC_RELEASE = 0) and (FPC_PATCH >= 1))))}  
   {$DEFINE FPC_VER_201_PLUS}  
 {$ENDIF}  
{$ifdef FPC_VER_201_PLUS}  
{$info At least this is version 2.0.1}  
{$else}  
{$fatal Problem with version check}  
{$endif}  

It should do what you require, but you'll have to adjust the figures.

  • 1
    One of the reasons why fullversion (see below) was introduced, was because so many mistakes were made in crafting such expressions. Many such expressions broke when a new major number series (e.g. 2.5.x) was created/added. – Marco van de Voort Jan 22 '11 at 22:21