This doesn't compile, but should it?

Hi,

I use these types of conditional compilations in Delphi, shouldn’t they also compile in Oxygene ? I’ve worked around this before, but I thought I’d ask the question today…

The problem seems to be having conditional compilation that splits a begin / end block, even though the block is completed subsequently.

In the screenshot below, the first piece of logic doesn’t compile, the second does. It seems to be the lack of a matching end inside the “using MyFlag do begin” that trips things up, even though the subsequent conditional adds in the required end.

Oxygene version is 10.0.0.2485,.

Am I missing something ?

All the blocks in compiler conditionals must be compilable code in Oxygene. Theres a discussion thread somewhere there explaining the reasons and how to work.

HTH

1 Like

Thanks Donald,

I found Marc’s explanation here . At least I know it’s not me,

The way Elements handles ifdefs in v10 is that each IFDEF must be its own logical structure. you can nest an IFDEF in another code structure, or you can nest an other code structure inside Ean IFDEF, but you cannot have them “overlap”, say, as below.

{$IFDEF X}
for x := 0 to 5 do begin
do stuff
{$ENDIF}
do more stuff
{$IFDEF X}
end;
{$ENDIF}

The for loop must be inside the ifdef or the ifdef must be inside the for loop. That’s because in Elements, IFDEFs become regular code structures (because you can also write then using “ if defined("X") ”).

1 Like

You can also add the following line in the elements file, to have the old (Delphi compatible) use of {$if}:

<UseLegacyPreprocessor>True</UseLegacyPreprocessor>
1 Like

You really shouldn’t, though.

OK for a new project.
But if you need to import a huge code base, it’s too time consuming to correct them all. It also avoid to add bugs because of the conversion.