7
votes

I have various define statements for handling different Delphi versions in an include file. This include file is "included" in an unit. The compiler respects the defines given in the include file but the IDE not. This results in an addition of certain units to the uses clause which are can be already there - enclosed in a DEFINE compiler directive.

Therefore, if a unit is added which isn't available in pre Delphi XE3 you will have a big problem because if you let the IDE add the unit and can not compile it with a pre Delphi XE3 version which doesn't have that unit.

E.g. a project with one unit with an TActionList on it.

  1. MYINCLUDE.INC only one define {$DEFINE DELPHIXE3}

  2. A sample unit may look like

    unit Unit1;
    
    {$I MYINCLUDE.INC}                
    
    uses
       Winapi.Windows, 
       Winapi.Messages, 
       System.SysUtils, 
       System.Variants, 
       System.Classes, 
       Vcl.Graphics,
       Vcl.Controls, 
       Vcl.Forms, 
       Vcl.Dialogs,
       {$IFDEF DELPHIXE3} System.Actions, {$ENDIF}
       Vcl.ActnList;
      ...
    
  3. After a save the IDE adds System.Actions add the end of the uses list which in turn results in an Identifier redeclared compiler error. If you delete it the IDE will add it again the next save.

I have just reported that to QC #111178.

Is there a workaround for that bug?

Christian

1
IDE has always been a bit lousy parsing conditionals. I expect your QC report to be closed as designed. The issue has been raised again and again with always the same response.David Heffernan
IDE always mangled conditionals in *.dpk files but this issue is something new and disappointing.kludg
@Serg It always behaved this way in .pas files too. Nothing new here. Been like this since forever.David Heffernan
I would not bother too much, it applies to Delphi's built-in units, which you will often use elsewhere in your program. Just include them 'always'. For your own units Delphi won't do this.Jan Doggen
@JanDoggen System.Actions doesn't exist in XE2.David Heffernan

1 Answers

3
votes

Probably the easiest thing to do is to use the unit alias feature to help. In order for this to work you need different project settings for different compiler versions. For example, different .dpr and .dproj files for each supported compiler version.

In your XE2 project you define a unit alias like so:

System.Actions=Vcl.ActnList

In the XE3 project you omit that alias.

Then in your .pas file you can happily use System.Actions with no problems in either version of Delphi.

An even simpler solution is to create an empty unit named System.Actions that you only include in your project for XE2 builds.