Using PE Flags in Delphi

There was a discussion about using the PE flag IMAGE_FILE_LARGE_ADDRESS_AWARE and whether this is equivalent to compiling a program to 64 bit Windows target (no it’s not) in the German Delphi Praxis forum. This prompted me to have a look at what kind of flags can be specified and how to do that for a Delphi program.

A quick Bing search for SETPEFLAGS and Delphi also found a blog post by Halvard Vassbotn from 2006 about the IMAGE_FILE_RELOCS_STRIPPED PE flag.

Since one of my programs has recently started to throw out of memory
exceptions (when displaying large(!) data files) and our executables tend to be rather large anyway, I decided to add these PE flags to it.

  • IMAGE_FILE_LARGE_ADDRESS_AWARE – App can handle >2gb addresses
  • IMAGE_FILE_RELOCS_STRIPPED – Relocation info stripped from file

With the flags it already used …

  • IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP – If Image is on removable media, copy and run from the swap file
  • IMAGE_FILE_NET_RUN_FROM_SWAP – If Image is on Net, copy and run from the swap file.

… this resulted in the following SETPEFLAGS compiler directive in the .dpr file:


The result was as I hoped: No out of memory error any more when displaying a file that always caused one before. The executable size also shrank, but not as significantly as I had hoped: 9698 KB where before it was 9987 KB, but every little helps.

But there is another side effect I found today: Setting IMAGE_FILE_NET_RUN_FROM_SWAP not only makes Windows load the executable into the swap file when executing it but apparently every time it accesses it. Simply selecting it in Windows Explorer resulted in the Explorer Window freezing for a short time (it feels like several seconds but probably is just about one), the same delay happens when opening the Properties dialog (e.g. to check the version info). That does not happen, when the flag isn’t set.