KodeZwerg 54 Posted August 15, 2022 (edited) 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 August 15, 2022 by KodeZwerg correction Share this post Link to post
Remy Lebeau 1394 Posted August 16, 2022 (edited) 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 August 16, 2022 by Remy Lebeau Share this post Link to post
Fr0sT.Brutal 900 Posted August 16, 2022 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)} 1 Share this post Link to post
Uwe Raabe 2057 Posted August 16, 2022 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. 1 Share this post Link to post
Brian Evans 105 Posted August 17, 2022 (edited) 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 August 17, 2022 by Brian Evans Share this post Link to post
David Heffernan 2345 Posted August 17, 2022 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