Question

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

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top