Jump to content
Sign in to follow this  
Attila Kovacs

Having the same unit twice in the uses clause

Recommended Posts

given this

 

program Project1;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  Generics.Collections,
  System.Generics.Collections;

begin
end.

 

the ide will not complain, possibly msbuild

but with "dcc32 -NSSystem Project1.dpr"  it's an "Identifier redeclared".

 

Where’s the logic in that?

 

 

 

Share this post


Link to post

The IDE implicitly adds an alias for Generics.Collections=System.Generics.Collections which suppresses that error. Although not specified in the project itself, this alias is added in CodeGear.Common.targets.

Share this post


Link to post
12 minutes ago, Uwe Raabe said:

The IDE implicitly adds an alias for Generics.Collections=System.Generics.Collections which suppresses that error.

Supresses the error? Why?

Share this post


Link to post

If a unit is resolved by the -A option, any double occurrence is silently resolved, too. So, strictly speaking, the error is not suppressed in the sense of it is an error, but we don't show it, but rather internally resolved by removing the superfluous occurrences.

 

In my blog article Conditional Uses Clause Considered Harmful one of the suggestions (Solutions 2) actually makes use of this behavior.

Share this post


Link to post

I just don't understand why msbuild would ignore the duplicates, but dcc does not.

I added 'System' with -NS to dcc32, just like in the Project settings in the IDE where unit scope names are also set.

I would expect the same behavior.

 

Share this post


Link to post

The IDE as well as MSBuild are using the dproj file of your project, while the compiler only sees the dpr. At the end of the dproj file there is an import command for CodeGear.Delphi.Targets, which itself imports CodeGear.Common.Targets. The latter sets the UnitAliases given to the compiler.

  • Thanks 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×