Have an amazing solution built in RAD Studio? Let us know. Looking for discounts? Visit our Special Offers page!
News

The Strange Case of the VCL Forms ClientWidth and the Windows Versions PE Flags

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:

This is the simple code of the only button:

Now if you run this application with Delphi 11 (left) or with Delphi 10.4 (right) you’ll get different results:

2022_vcl_clientwidth_winversion-5032507

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:

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.


Coding Boot Camp

Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial   Upgrade Today

   Free Delphi Community Edition   Free C++Builder Community Edition

About author

Marco is one of the RAD Studio Product Managers, focused on Delphi. He's the best selling author of over 20 books on Delphi.

6 Comments

Leave a Reply to Paul Westaway Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

IN THE ARTICLES