0

I'm using Delphi XE3, I have many project which contain a rtl unit in DPK file (necessary to set {$SetPEFlags IMAGE_FILE_NET_RUN_FROM_SWAP}), so their DPK looks like this:

requires
  { ... };

contains
  { ... },
  Winapi.Windows;

{$SetPEFlags IMAGE_FILE_NET_RUN_FROM_SWAP}

end.

Recently I added the projects by selecting the DPKs from Windows explorer and using drag-and-drop to add them in a project group, now the project tree of some projects (not all of them) looks like this:

project tree

How can I prevent Winapi.Windows.pas from showing in the project tree?

  • 2
    Simplest way is to stop importing the Windows unit and then do `const IMAGE_FILE_NET_RUN_FROM_SWAP = $0800` in your dpk file. – David Heffernan Sep 16 '21 at 11:15
  • @DavidHeffernan is this the only way? I'd also like to understand *why* sometimes it adds the Windows unit.. is this some sort of Delphi bug or there's an option I can set? – Marina Finetti Sep 16 '21 at 13:02
  • The other way is to put the `$SetPEFlags` in a unit that is compiled in to your package, but you have to make sure that it is in your package, and not referenced dynamically in a different package. I would absolutely do it the way I said in my comment. – David Heffernan Sep 16 '21 at 13:14
  • 1
    @MarinaFinetti Why is the `Winapi.Windows` unit in your `contains` list to begin with? It doesn't belong there at all (unless you are actually making modifications to `Winapi.Windows.pas`), it should be in a `uses` clause instead. Or, just hard-code the `IMAGE_FILE_NET_RUN_FROM_SWAP` flag yourself as a local constant, like David suggested. – Remy Lebeau Sep 16 '21 at 17:39
  • @DavidHeffernan @RemyLebeau how can I declare `uses` or `const` clauses in DPK file? Everywhere I put them produces a compiling error.. – Marina Finetti Sep 20 '21 at 11:13
  • This is why you are best doing what I said right at the very start – David Heffernan Sep 20 '21 at 11:25
  • @DavidHeffernan that's what I'm trying to do, declaring `const IMAGE_FILE_NET_RUN_FROM_SWAP = $0800` in my dpk file, but I keep on having compiling errors – Marina Finetti Sep 22 '21 at 08:17
  • 1
    You are right, can't even declare a const in a dpk file. So that leaves you with `{$SetPEFlags $0800}` and a comment! Or you could use a post-build action to call editbin to set the flags, but I don't think that's better. – David Heffernan Sep 22 '21 at 08:21

1 Answers1

0

The reason why Delphi shows Winapi.Windows.pas in your project as being so deep within the project tree is the fact that the location of the said file is not within your project folder or any of its sub-folders so it needs to be added with absolute path information.

But units that reside within your project folder or any of its sub-folders can be added with relative path information. In such case there probably won't bee so deep tree structure unless you also have deep folders structure within your project directory.

SilverWarior
  • 7,372
  • 2
  • 16
  • 22