Only a few developers are aware that the behavior of Windows applications varies depending on the Windows versions declared in their PE headers in the EXE file. Delphi customers are reporting some unexpected effects as a result of a core configuration change in Delphi 11 that went unnoticed by most.
A Windows application is stored in an EXE file in the PE format, which includes a number of PE flags that determine the application behavior in many areas. One of these flags is the Windows version. Over the last year, the Embarcadero R&D team has started to witness that some Windows APIs (particularly related to the windows non-client area, but also around High DPI) were not behaving correctly in the latest versions of the operating system.
This was due to the fact that Delphi applications by default were using fairly old Windows versions in the PE flags, despite having dropped official support for versions like Windows XP. For this reason, to address some genuine API issues, in Delphi 11 Alexandria Embarcadero switched the PE flags Windows versions to 6.0.
While this change is beneficial in many areas, it can cause some significant changes in the behavior of existing VCL applications. One visible example is in the size of the border of the window for in case of a bsDialog form border style. The border style becomes bigger and therefore the difference between the form width and its client width changes. Same for the height.
As a practical example, I’ve created a very simple VCL application with a button and two labels. Notice that the main form has this setting:
[crayon-672aadb5329eb661782703/]
This is the simple code of the only button:
[crayon-672aadb5329f2517817322/]
Now if you run this application with Delphi 11 (left) or with Delphi 10.4 (right) you’ll get different results:
With an overall form of 1000 width, I get 974 client pixels in Delphi 11, compared to 994 in older versions. That is because the border is thicker. The positive side is that the title bar has better spacing and the window caption is not crammed to the border (which was one of the bugs reported for older versions of Delphi). In other words, the window on the left, built in Delphi 11, is better looking in terms of the non-client area.
By the way, notice that by default the form client width “wins” over the form width. Without the line to set the Width, in both cases you’d have the same client width and a different form width. So your components positioning (in case of absolute values) won’t be affected. It’s only by manually setting the Width that the Client Width is set to value different from the past.
Now if for any reason you want to stick with the old behavior — maybe just because it is how your existing application works — you don’t need to roll back to Delphi 10.4. The PE flags can be controlled by the compiler and linker. In fact, I obtained the image on the right (the old version) by using Delphi 11 and adding to the main project file the following two compiler directives:
[crayon-672aadb5329f3354569203/]
With this code, you can revert the default change Embarcadero applied to Delphi 11 and keep using the older Windows version PE flags and the old behavior, for the good or the bad. Your choice.
Do you want to make your own VCL Forms?
Try out the IDE Software and make the most of it. Request a Free Trial here.