Jump to content
KodeZwerg

Conditional compiling - Delphi has a bug

Recommended Posts

I did discovered a bug i guess by accident.
I wanted to expand my own .inc file to support FreePascal but compiler did not let me.
 

{$IF Defined(FPC)}
  {$IF Declared(FPC_VERSION)}
    {$IF FPC_VERSION >= 3}  // [Pascal Error] kz.inc(80): E2026 Constant expression expected
      {$DEFINE UNICODE}
    {$IFEND FPC_VERSION}
  {$IFEND FPC_VERSION}
{$IFEND FPC}

A fix was to do it like this, himitsu from german Delphi-Praxis came up with:
 

{$IF Defined(FPC) and Declared(FPC_VERSION) and (FPC_VERSION >= 3)}
  {$DEFINE UniCode} { FreePascal UniCode support }
{$IFEND}

I did open a Report -> Conditional Compiling dont work as expect

If you think i was wrong, please correct me.

Edited by KodeZwerg
correction

Share this post


Link to post
4 hours ago, KodeZwerg said:

I wanted to expand my own .inc file to support FreePascal but compiler did not let me.


{$IF FPC_VERSION >= 3}  // [Pascal Error] kz.inc(80): E2026 Constant expression expected

 

This seems to be the opposite of documented behavior in Delphi: https://docwiki.embarcadero.com/RADStudio/en/IF_directive_(Delphi)

Quote

If the identifiers referenced in the conditional expression do not exist, the conditional expression will be evaluated as False:


  {$IF NoSuchVariable > 5}
    Writeln('This line doesn''t compile');
  {$IFEND}

So, {$IF FPC_VERSION >= 3} SHOULD just evaluate to False, and if it is not then this is likely a regression.

Edited by Remy Lebeau

Share this post


Link to post
6 hours ago, Remy Lebeau said:

So, {$IF FPC_VERSION >= 3} SHOULD just evaluate to False, and if it is not then this is likely a regression.

That IF shouldn't be evaluated at all as it lays inside falsy outer block {$IF Declared(FPC_VERSION)}

  • Like 1

Share this post


Link to post
7 hours ago, Remy Lebeau said:

So, {$IF FPC_VERSION >= 3} SHOULD just evaluate to False, and if it is not then this is likely a regression.

If it is a regression, it dates back to Delphi 7 (cannot test for Delphi 6).

Given that conditional expressions were introduced in Delphi 6 I wonder if that has ever worked.

  • Sad 1

Share this post


Link to post

The help for the IF directive gives an example of such a construct all on one line instead of split into two IF's. I would suggest trying it that way as it seems to not like just the number check on it's own. 

IF directive (Delphi) - RAD Studio (embarcadero.com) :

  {$IF Declared(FireMonkeyVersion) and (FireMonkeyVersion > 16.0)}
    ...
  {$IFEND}
Edited by Brian Evans

Share this post


Link to post
3 hours ago, Brian Evans said:

The help for the IF directive gives an example of such a construct all on one line instead of split into two IF's.

You can see exactly this in the original post above. That's not the question being asked though. 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×