Jump to content
Ramu

Form.PixelsPerInch is no longer used in Delphi 10.3 while scaling

Recommended Posts

Hi All,

In previous Delphi versions, when I change the pixels per inch value in a DFM file and run the application, all the controls got adjusted to the current screen PPI.

But in 10.3, when I change the PixelPerInch value, controls are not getting adjusted to the screen PPI. 

This is causing the problem to our application. We have recently moved our project from Delphi 2007 to Delphi 10.3.
Few forms are developed at PPI 120. These forms when opened in the screen, whose PPI is 96, controls are getting scaled in Delphi 2007. But in 10.3, it is not happening.

Steps to reproduce :
1. Create a forms application with a simple label in Delphi 10.3 at PPI 96.
2. Manually open the form in an editor. Change PPI to 120, and label height and width (value*120/96)
3. Open the form in 10.3 IDE. You will see that the values are not scaled. Even at run time, the values are not getting scaled.  

But if you open this project in Delphi 2007, values are getting scaled to 96. 

I wonder how the scaling happens in Delphi 10.3.

Thanks and Regards

Edited by Ramu

Share this post


Link to post

Make this setting for your previous version project.
If this doesn't solve your problem, you should take advantage of "SetProcessDPIAware" api.

 

 

Capture.JPG

Share this post


Link to post

Thanks, Turan

The setting is not adjusting any values. I have tried with system aware, per-monitor, and per-monitor v2. Nothing is working for me.



 

Edited by Ramu

Share this post


Link to post

Try with a fresh project. If that succeeds, find out the differences to your project.

Share this post


Link to post

@Uwe Raabe, I have tried with the fresh project and followed the steps mentioned in my first post. In this project also, values are not getting scaled.

Please find my sample project in the attachment.

TestProject.zip

Thanks and Regards

Edited by Ramu

Share this post


Link to post
23 minutes ago, Ramu said:

values are not getting scaled.

Perhaps we are talking about different things. The settings for DPI awareness are only valid when running the application, not when designing it.

 

A form designed with PixelsPerInch set to 120 is not scaled when opened In Delphi 10.3 on a system with PixelsPerInch=96. You already found that out. That is different to older versions and I am not aware of any setting to change that. You need to open the form with an older version of Delphi (still implementing this behavior) on the 96 dpi system, save the form with 96 dpi and you are good.

 

In case you consider waiting for Embarcadero to fix this, there already is QP entry 15141 closed as Won't Fix.

 

 

Share this post


Link to post

Thank you, Uwe Raabe.

Though it is hard to believe that Scaling is not happening in Delphi 10.3 if the forms designed at 120 PPI, at least we now know what to do next.

This means we need to make sure that all the forms to be designed and changes to existing forms to be done at PPI 96?

If we design the forms in 96 PPI and open the application in 120 PPI screen, will the controls get scaled?

Regards,

Share this post


Link to post
25 minutes ago, Ramu said:

If we design the forms in 96 PPI and open the application in 120 PPI screen, will the controls get scaled?

Yes, that is what the DPI options in Manifest are for. If you have multiple monitors with different DPI and a more recent Windows 10 version I suggest the Per Monitor v2 setting.

Share this post


Link to post
39 minutes ago, Uwe Raabe said:

Yes, that is what the DPI options in Manifest are for. If you have multiple monitors with different DPI and a more recent Windows 10 version I suggest the Per Monitor v2 setting.

As far as my understanding, DPI options in the manifest are used, if we move the application opened in one monitor to another monitor.

I may also be wrong as I am new to these concepts. Please correct me if I am wrong.

But in our case, we have an application(EXE) and that EXE can be opened in different screens independently, not moving from one monitor to another. 

Suppose if the EXE was designed in 96 PPI machine, gave that EXE to customers and customers are trying to open that EXE in 120PPI screen, will the controls be scaled according to 120 PPI?

Thanks and Regards

Edited by Ramu

Share this post


Link to post

That should work with PerMonitor v2 as well. The application reads the DPI from the current monitor (even if there is only one) and scales accordingly.

Share this post


Link to post

I develop on a machine with 200 and 120 dpi screen and simply make sure that all the form DPI settings are set to 96.  In Delphi 10.3, with per-monitor DPI enabled, this usually 'just works'.  When it does not, the cause is usually a component which does not handle the 'before' and 'after' MonitorDpiChange events properly or at all.  There are fewer of these around these days;  but we still have a few which required either source modification, or adjustment of their settings by handling these events in our application.

Share this post


Link to post

Thanks @Uwe Raabe    @timfrost

I have tried to analyze the cause of not scaling in Delphi 10.3. 

In Delphi 10.3, they have added one more parameter called FCurrentPPI in the TControl class in VCL.Controls and are assigning default value as "Winapi.Windows.USER_DEFAULT_SCREEN_DPI" at the time of creating each control.  Winapi.Windows.USER_DEFAULT_SCREEN_DPI is returning 96 in my machine(96PPI). At the time of scaling, they are comparing FCurrentPPI with new PPI(current screen PPI). Since both are coming equal, they are not scaling the controls. 

They have added one more function GetDesignDPI and are calling only if FcurrentPPI is equal to 0. But at the time of creating controls, they are assigning 
Winapi.Windows.USER_DEFAULT_SCREEN_DPI as default value. I wonder when this function will be used?

I think, Winapi.Windows.USER_DEFAULT_SCREEN_DPI in 120 PPI machine returns 120 and new PPI is also 120. I wonder how scaling happens in 120 PPI machine.
In 120 PPI machine, scaling will happen only if Winapi.Windows.USER_DEFAULT_SCREEN_DPI returns 96.

Thanks and Regards

Edited by Ramu

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×