How do I tell Delphi to use the local project's Security.pas file rather than Winapi.Security.pas in DXS?

713 Views Asked by At

Delphi 10 Seattle introduces Winapi.Security.pas. The project (a package) I'm trying to upgrade already has a Security.pas file. Short of removing Winapi from the list of scope names for the project (huge undesirable ripple effect), is there a way to tell the IDE and compiler to use the project's Security.pas file instead of Winapi.Security.pas?

I already tried renaming the projects Security.pas, but that caused even more problems with the compiler generating errors that have nothing to do with the code it was complaining about, so that's a rathole I'd rather not go down right now. This project builds just fine unchanged in XE7, FWIW, so this isn't due to any code changes in the project.

Updates:

  • Renaming the file and using a unit alias doesn't work.
  • The compiler behavior for a package differs from an application.
4

There are 4 best solutions below

5
Jim McKeeth On

If you put both Winapi.Security and your local Security in the same uses clause then you are able to access the members of both of them without issue. If you put them in separate uses clauses (Interface vs. Implementation) then you will get the error:

E2004 Identifier redeclared: 'Winapi.Security'

If I only include Security.pas in the uses clause (and it is included in the project) then it accesses its members just fine.

Perhaps I need more information about what error you are running into? I'll send you a sample project that shows this working.

3
djsoft On

Open project settings, in the Delphi Compiler section remove "Winapi" from "Unit scope names".

This way, when you need the Security unit shipped with Delphi, you'll have to write Winapi.Security, and if you write Security, it will use your custom Security unit.

5
David Heffernan On

Looks like this might actually be related to the Winapi.Security unit rather than something as generic as you suggest in the question. For instance, the following package compiles just fine:

package Package1;

requires
  rtl;

contains
  Windows in 'Windows.pas'; // blank unit named Windows.pas in project folder

end.

Note that I have, like you, included Winapi in the project's list of unit scope names.

On the other hand, this package does not compile:

package Package1;

requires
  rtl;

contains
  Security in 'Security.pas'; // blank unit named Security.pas in project folder

end.

The compiler fails with:

[dcc32 Error] Package1.dpk(7): E2200 Package 'rtl' already contains unit 'Winapi.Security'

If the issue was purely related to unit scope names then either both packages would compile, or both would fail. Hence my conclusion that there is something out of whack with Winapi.Security.

I can find no source code for Winapi.Security. I wonder what it actually is. [Nicholas Ring located the source for me, inside the rtl\win\winrt directory.]

Anyway, I think it's time to submit a QP report. The package below that fails to compile is probably the starting point for that QP report. [Your submitted report is here RSP-12469.]

It seems clear to me that in the short term you must rename your unit if you wish to adopt Seattle.

FWIW, here are some other units that behave the same way as Winapi.Security:

  • Winapi.ApplicationModel
  • Winapi.CommonTypes
  • Winapi.Devices
  • Winapi.Foundation
  • Winapi.Gaming
  • Winapi.Globalization
  • Winapi.GraphicsRT
  • Winapi.Management
  • Winapi.Media
  • Winapi.Networking
  • Winapi.Storage
  • Winapi.UI
  • Winapi.WebRT

These are all newly added WinRT units which I expect is important.

4
OBones On

I might well be wrong, but I believe that if Security.pas is in the uses clause of the dpr file, along with its full path, it will be preferred over whichever file can be found via the namespaces and search paths.