Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2010-10

Fwd: Delphi incompatible conditionals?

8 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Mark Daems

Hi,

I'm trying to add following conditional code to the top of a unit that should compile in fpc and in delphi:

{$IFDEF FPC}
 {$IFNDEF ver1}
   {$IF (fpc_version>2) or (fpc_version=2) and (fpc_release>3)}      {$info FPC version >= 2.4.0 : Should work}    {$ELSE}
     {$warning FPC versions below 2.4 are not supported. However : give it a try, you never know.}
   {$IFEND}
 {$ELSE}
   {$fatal FPC version 1 isn't supported at all}  {$ENDIF}
{$ENDIF}

This seems to work well in fpc, however the delphi (7 and 2009) compiler complains on the {$IF ...} line.
     [DCC Error] Zeos.inc(49): E2026 Constant expression expected

Replacing the {$IF ...} line by
   {$IF Defined(fpc_version) and ((fpc_version>2) or (fpc_version=2) and (fpc_release>3))}
seems to solve the previous problem, however then the compiler outputs this warning 4 times for every occurence of this code:      [DCC Warning] Zeos.inc(49): W1023 Comparing signed and unsigned types - widened both operands
Because I want to use this code in an include file for every unit in the project this becomes very messy.

And it's a weird behaviour, because it's all within an {$IFDEF FPC} construct. Why does delphi even try to interprete it?

Somebody knows how to avoid the problem?

Mark

Reply by email

Juha Manninen (gmail
to Mark Daems
Mark Daems wrote 5 lines
... And it's a weird behaviour, because it's all within an {$IFDEF FPC} construct. Why does delphi even try to interprete it? Somebody knows how to avoid the problem?

Try this instead:

{$IFNDEF FPC}
  // Can be empty
{$ELSE}
  ...
{$ENDIF}

I got feedback for the Delphi converter in Lazarus about this same problem. Now the converter always adds IFNDEF instead of IFDEF to the code.

Juha

Reply by email

Marco van de Voort
to Mark Daems: I'm trying to add following conditional code to the top of a unit that should compile in…

In our previous episode, Mark Daems said:

Show quoted text 11 lines
I'm trying to add following conditional code to the top of a unit that should compile in fpc and in delphi: This seems to work well in fpc, however the delphi (7 and 2009) compiler complains on the {$IF ...} line. ? ? ?[DCC Error] Zeos.inc(49): E2026 Constant expression expected Replacing the {$IF ...} line by ? ?{$IF Defined(fpc_version) and ((fpc_version>2) or (fpc_version=2) and (fpc_release>3))}

I also noticed that. Strange. (delphi XE btw)

Show quoted text 6 lines
seems to solve the previous problem, however then the compiler outputs this warning 4 times for every occurence of this code: ? ? ?[DCC Warning] Zeos.inc(49): W1023 Comparing signed and unsigned types - widened both operands Because I want to use this code in an include file for every unit in the project this becomes very messy.

Try longint(3) and longint(2).

And it's a weird behaviour, because it's all within an {$IFDEF FPC} construct. Why does delphi even try to interprete it? Somebody knows how to avoid the problem?

I think it belongs on the Embarcadero buglist more than here. OTOH, they will only fix it in the current or next version. So that's why I tried till I got above workaround.

Still, it might be worth a report, otherwise stuff never gets fixed. And that goes both for FPC and Delphi :-)

Reply by email

Mark Daems
Show quoted text 23 lines
From: "Juha Manninen (gmail)" To: "FPC-Pascal users discussions" Date: Fri, 1 Oct 2010 20:04:18 +0300 Subject: Re: [fpc-pascal] Fwd: Delphi incompatible conditionals? On Friday 01 October 2010 19:33:48 Mark Daems wrote: > ... > And it's a weird behaviour, because it's all within an {$IFDEF FPC} > construct. Why does delphi even try to interprete it? > > Somebody knows how to avoid the problem? Try this instead: {$IFNDEF FPC}  // Can be empty {$ELSE}  ... {$ENDIF} I got feedback for the Delphi converter in Lazarus about this same problem. Now the converter always adds IFNDEF instead of IFDEF to the code. Juha

Sorry Juha,
This doesn't keeps trying to interprete all {$IF
...} conditions in the file, even if it doesn't make sense because of surrounding conditions.

Show quoted text 5 lines
From:  (Marco van de Voort) To: FPC-Pascal users discussions Date: Fri, 1 Oct 2010 19:52:36 +0200 (CEST) Subject: Re: [fpc-pascal] Fwd: Delphi incompatible conditionals? In our previous episode, Mark Daems said:

...

Try longint(3) and longint(2).

How should I do that? The place where the file containing the conditions is included doesn't allow for defining constants as it's the very first line in the unit code. Even before the uses clause in the interface section. Actually the problem is Delphi doesn't find the constant definitions, so it's guessing the data type of fpc_version and fpc_release.

Still, it might be worth a report, otherwise stuff never gets fixed. And that goes both for FPC and Delphi :-)

This isn't an FPC handles this exactly as expected. Unless they invent some new FPC only version checking directive allowing for syntax like {$IFVERSION < 2.4}...{$ENDIFVERSION}, {$IFVERSION 2.4}...{$ENDIFVERSION} and {$IFVERSION 2}...{$ENDIFVERSION}
That would solve the Delphi problem completely as no {$IF} with constants is involved anymore. Provided you can make sure all old fpc versions get this behaviour as well. Which brings us back to ... impossible to solve.

Thanks for trying to resolve this issue, but I think I'll add the checks to the top of the fpc packages files. In that case only Lazarus will see them, but people using the units directly in fpc will not get the message...

Mark

Reply by email

Martin
to Mark Daems: I'm trying to add following conditional code to the top of a unit that should compile in…
Mark Daems wrote 21 lines
Hi, I'm trying to add following conditional code to the top of a unit that should compile in fpc and in delphi: {$IFDEF FPC} {$IFNDEF ver1} {$IF (fpc_version>2) or (fpc_version=2) and (fpc_release>3)} {$info FPC version>= 2.4.0 : Should work} {$ELSE} {$warning FPC versions below 2.4 are not supported. However : give it a try, you never know.} {$IFEND} {$ELSE} {$fatal FPC version 1 isn't supported at all} {$ENDIF} {$ENDIF} This seems to work well in fpc, however the delphi (7 and 2009) compiler complains on the {$IF ...} line. [DCC Error] Zeos.inc(49): E2026 Constant expression expected
if you can put it after the uses clause (so you can have a const
section, the following worked for me:
{$IFNDEF FPC}
const fpc_version=1; fpc_release=1;
{$ENDIF}
// your code below
{$IFDEF FPC}
  {$IFNDEF ver1}
    {$IF (fpc_version>2) or (fpc_version=2) and (fpc_release>3)}
      {$info FPC version >= 2.4.0 : Should work}
    {$ELSE}
      {$warning FPC versions below 2.4 are not supported. However :
give it a try, you never know.}
    {$IFEND}
  {$ELSE}
    {$fatal FPC version 1 isn't supported at all}
  {$ENDIF}
{$ENDIF}
Show quoted text 7 lines
Replacing the {$IF ...} line by {$IF Defined(fpc_version) and ((fpc_version>2) or (fpc_version=2) and (fpc_release>3))} seems to solve the previous problem, however then the compiler outputs this warning 4 times for every occurence of this code: [DCC Warning] Zeos.inc(49): W1023 Comparing signed and unsigned types - widened both operands
    {$IF Defined(fpc_version) and ((fpc_version>word(2)) or
(fpc_version=word(2)) and (fpc_release>word(3)))}

gets rid of the warnings

Reply by email

Marco van de Voort
to Mark Daems: This doesn't keeps trying to interprete all {$IF ...} conditions in the file, even if it…

In our previous episode, Mark Daems said:

Show quoted text 7 lines
... > Try longint(3) and longint(2). > How should I do that? The place where the file containing the conditions is included doesn't allow for defining constants as it's the very first line in the unit code.
{$if ...   $FPCVERSION>LONGINT(3) }

See also Martin's solution, which essentially the same.

Reply by email

Mark Daems
Show quoted text 20 lines
---------- Doorgestuurd bericht ---------- From: Martin if you can put it after the uses clause (so you can have a const section, the following worked for me: {$IFNDEF FPC} const fpc_version=1; fpc_release=1; {$ENDIF} // your code below {$IFDEF FPC}  {$IFNDEF ver1}   {$IF (fpc_version>2) or (fpc_version=2) and (fpc_release>3)}     {$info FPC version >= 2.4.0 : Should work}   {$ELSE}     {$warning FPC versions below 2.4 are not supported. However : give it a try, you never know.}   {$IFEND}  {$ELSE}   {$fatal FPC version 1 isn't supported at all}  {$ENDIF} {$ENDIF}

Not an option : uses clauses may depend on the defines in the file.

  {$IF Defined(fpc_version) and ((fpc_version>word(2)) or (fpc_version=word(2)) and (fpc_release>word(3)))} gets rid of the warnings

Works great on Delphi, but doesn't compile in fpc with following message:

Zeos.inc(49,9) Error: Compile time expression: Wanted INTEGER but got
STRING at "2 > word"

Also tried Marcov's Longint(2) instead of word(2). Same error.

Mark

Reply by email