Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: A Delphi Developers Guide for 4K Displays



Permlink Replies: 10 - Last Post: Nov 25, 2014 1:06 PM Last Post By: Dalija Prasnikar
Alexander Halser


Posts: 7
Registered: 11/22/99
A Delphi Developers Guide for 4K Displays
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 18, 2014 10:11 AM
After getting through this myself for our own product (we are still not done), I decided to put the experiences into a tutorial, how to make a Delphi application dpi-aware and, more importantly, what to do to make it really work.

This tutorial intends to help you getting your Delphi Windows applications ready for ultra-high resolution ("4K") displays. It covers all topics from Delphi's UI scaling on systems with large fonts to per-monitor DPI-awareness on Windows 8.1:

* Dots per Inch (DPI) explained
* Windows and DPI, Delphi and DPI
* Testing high resolutions
* DPI virtualization in Windows
* Windows 8.1 multi-montor DPI scaling
* Declaring DPI-awareness in Delphi
* Flipping DPI at runtime on Windows 8.1

The 38 pages tutorial is in PDF format and includes a Delphi XE6/7 demo application with source that is fully DPI-aware and scales at runtime on Windows 8.1 with multiple monitors.

Download link:
http://www.helpandmanual.com/downloads_delphi.html
Steve Thackery

Posts: 151
Registered: 4/29/06
Re: A Delphi Developers Guide for 4K Displays [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 18, 2014 12:43 PM   in response to: Alexander Halser in response to: Alexander Halser
Alexander Halser wrote:

After getting through this myself for our own product (we are still
not done), I decided to put the experiences into a tutorial, how to
make a Delphi application dpi-aware and, more importantly, what to do
to make it really work.


Tremendously helpful and informative - thank you!

--
SteveT
Markus Humm

Posts: 5,113
Registered: 11/9/03
Re: A Delphi Developers Guide for 4K Displays [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 19, 2014 12:22 PM   in response to: Alexander Halser in response to: Alexander Halser
Am 18.11.2014 19:17, schrieb Alexander Halser:
After getting through this myself for our own product (we are still not done), I decided to put the experiences into a tutorial, how to make a Delphi application dpi-aware and, more importantly, what to do to make it really work.

This tutorial intends to help you getting your Delphi Windows applications ready for ultra-high resolution ("4K") displays. It covers all topics from Delphi's UI scaling on systems with large fonts to per-monitor DPI-awareness on Windows 8.1:

* Dots per Inch (DPI) explained
* Windows and DPI, Delphi and DPI
* Testing high resolutions
* DPI virtualization in Windows
* Windows 8.1 multi-montor DPI scaling
* Declaring DPI-awareness in Delphi
* Flipping DPI at runtime on Windows 8.1

The 38 pages tutorial is in PDF format and includes a Delphi XE6/7 demo application with source that is fully DPI-aware and scales at runtime on Windows 8.1 with multiple monitors.

Download link:
http://www.helpandmanual.com/downloads_delphi.html

Hello,

while it's a nice and surely helpful tutorial I found one thing a bit
strange:

If yoh have this multi display DPI awarenes and move your window around
several times it causes the scaling to go off, right? That's because
scaling is always done from the current font size in pixel and so
runding errors accumulate.

Couldn't you just get that value on form create, store it in a field of
the form and recalculate when needed based on that one? (ok, you might
need to save current DPI value at form create as well)? Wouldn't that
solve this one?

And: has anybody already made a QC or QualityPortal request about
natively supporting and handling this new Win 8.1 message? We all could
spare to roll our own solution for this. It would also be nice if the
change I outlined to not accumulating rounding errors could be
incorporated in such a solution.

Greetings

Markus
Alexander Halser


Posts: 7
Registered: 11/22/99
Re: A Delphi Developers Guide for 4K Displays [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 19, 2014 1:58 PM   in response to: Markus Humm in response to: Markus Humm
Markus Humm wrote:
Couldn't you just get that value on form create, store it in a field of
the form and recalculate when needed based on that one? (ok, you might
need to save current DPI value at form create as well)? Wouldn't that
solve this one?

You could, although Form.PixelsPerInch gets changed at an early stage, before the constructor Create is called. But... what for? You are still scaling from the current size to a new one. ChangeScale() takes two parameters, a multiplier and a divisor... and that scales the form and fonts and all controls on it, in a cascading iteration. Every control gets a new size and position when this method is being applied and the values are integers. They are unfortunately truncated. If ChangeScale() rounded them instead, the result would be more stable. Not 100%, but with much less rounding differences. I assume that the reason for using MulDiv() in the calculation is speed.

To be able to scale again from the original design, you not only need to remember the original DPI value of the form, but the form's position and size as well. And margins, constraints, etc. And the corresponding properties of each and every control on this form. You'd basically have to reload the original form from the resource, do a new ChangeScale() to the desired scale and replace the form in memory with that. I could imagine a tiny problem with dynamically created controls and components though...

For a practical solution, I'd rather scale by the DPI difference in order to avoid rounding differences with font sizes in pixels. But that's my take on it, because we change the fonts in our application dynamically anyway, so the Delphi way of scaling the form is less useful for us. That requires some space between controls to accomodate larger-than-expected fonts. For recurring scales on Windows 8.1, it would be helpful to patch Vcl.Forms.pas and round the results instead of truncating them. I tested that and it worked well enough.

A more thorough solution would be to save these properties as floats (or store them as twips), at least at runtime. This would survive any scale.
Dalija Prasnikar

Posts: 2,325
Registered: 11/9/99
Re: A Delphi Developers Guide for 4K Displays [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 20, 2014 12:03 PM   in response to: Markus Humm in response to: Markus Humm
Markus Humm wrote:

And: has anybody already made a QC or QualityPortal request about
natively supporting and handling this new Win 8.1 message? We all could
spare to roll our own solution for this. It would also be nice if the
change I outlined to not accumulating rounding errors could be
incorporated in such a solution.

VCL and FireMonkey lack Per-Monitor DPI support for Windows 8.1
https://quality.embarcadero.com/browse/RSP-9679

There is also report for Delphi IDE high DPI awareness
https://quality.embarcadero.com/browse/RSP-9678

--
Dalija Prasnikar
Markus Humm

Posts: 5,113
Registered: 11/9/03
Re: A Delphi Developers Guide for 4K Displays [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 24, 2014 11:32 AM   in response to: Dalija Prasnikar in response to: Dalija Prasnikar
Am 20.11.2014 21:03, schrieb Dalija Prasnikar:
Markus Humm wrote:

And: has anybody already made a QC or QualityPortal request about
natively supporting and handling this new Win 8.1 message? We all could
spare to roll our own solution for this. It would also be nice if the
change I outlined to not accumulating rounding errors could be
incorporated in such a solution.

VCL and FireMonkey lack Per-Monitor DPI support for Windows 8.1
https://quality.embarcadero.com/browse/RSP-9679

There is also report for Delphi IDE high DPI awareness
https://quality.embarcadero.com/browse/RSP-9678

Hello,

I had some private mail conversation with Marco about this topic lately
pointing him to the URL of this tutorial.

He said he had read it and for XE8 some improvements in this area are
being planned or at least looked at which are regarding font sizing and
the IDE would profit from them as well.

Greetings

Markus
Dalija Prasnikar

Posts: 2,325
Registered: 11/9/99
Re: A Delphi Developers Guide for 4K Displays [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 24, 2014 11:39 AM   in response to: Markus Humm in response to: Markus Humm
Markus Humm wrote:
Am 20.11.2014 21:03, schrieb Dalija Prasnikar:
Markus Humm wrote:

And: has anybody already made a QC or QualityPortal request about
natively supporting and handling this new Win 8.1 message? We all could
spare to roll our own solution for this. It would also be nice if the
change I outlined to not accumulating rounding errors could be
incorporated in such a solution.

VCL and FireMonkey lack Per-Monitor DPI support for Windows 8.1
https://quality.embarcadero.com/browse/RSP-9679

There is also report for Delphi IDE high DPI awareness
https://quality.embarcadero.com/browse/RSP-9678

Hello,

I had some private mail conversation with Marco about this topic lately
pointing him to the URL of this tutorial.

He said he had read it and for XE8 some improvements in this area are
being planned or at least looked at which are regarding font sizing and
the IDE would profit from them as well.

Great news.

--
Dalija Prasnikar
Markus Humm

Posts: 5,113
Registered: 11/9/03
Re: A Delphi Developers Guide for 4K Displays [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 24, 2014 12:43 PM   in response to: Dalija Prasnikar in response to: Dalija Prasnikar
Am 24.11.2014 20:39, schrieb Dalija Prasnikar:
Markus Humm wrote:
Am 20.11.2014 21:03, schrieb Dalija Prasnikar:
Markus Humm wrote:

And: has anybody already made a QC or QualityPortal request about
natively supporting and handling this new Win 8.1 message? We all could
spare to roll our own solution for this. It would also be nice if the
change I outlined to not accumulating rounding errors could be
incorporated in such a solution.

VCL and FireMonkey lack Per-Monitor DPI support for Windows 8.1
https://quality.embarcadero.com/browse/RSP-9679

There is also report for Delphi IDE high DPI awareness
https://quality.embarcadero.com/browse/RSP-9678

Hello,

I had some private mail conversation with Marco about this topic lately
pointing him to the URL of this tutorial.

He said he had read it and for XE8 some improvements in this area are
being planned or at least looked at which are regarding font sizing and
the IDE would profit from them as well.

Great news.

Yep. ;-) (writing this while installing XE7 update 1 which is great
except the fact that they didn't change status of some QP reports which
were fixed in update 1 to fixed - not sure what the politics about those is)

Greetings

Markus
Dalija Prasnikar

Posts: 2,325
Registered: 11/9/99
Re: A Delphi Developers Guide for 4K Displays [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 25, 2014 2:11 AM   in response to: Markus Humm in response to: Markus Humm
Markus Humm wrote:
Am 24.11.2014 20:39, schrieb Dalija Prasnikar:
Markus Humm wrote:
Am 20.11.2014 21:03, schrieb Dalija Prasnikar:
Markus Humm wrote:

And: has anybody already made a QC or QualityPortal request about
natively supporting and handling this new Win 8.1 message? We all could
spare to roll our own solution for this. It would also be nice if the
change I outlined to not accumulating rounding errors could be
incorporated in such a solution.

VCL and FireMonkey lack Per-Monitor DPI support for Windows 8.1
https://quality.embarcadero.com/browse/RSP-9679

There is also report for Delphi IDE high DPI awareness
https://quality.embarcadero.com/browse/RSP-9678

Hello,

I had some private mail conversation with Marco about this topic lately
pointing him to the URL of this tutorial.

He said he had read it and for XE8 some improvements in this area are
being planned or at least looked at which are regarding font sizing and
the IDE would profit from them as well.

Great news.

Yep. ;-) (writing this while installing XE7 update 1 which is great
except the fact that they didn't change status of some QP reports which
were fixed in update 1 to fixed - not sure what the politics about those is)

Changing status of QP reports - there is no policy, you just have to remind them to do so :)

Usually it can take them few days after the release/update to do so on their own, but
if it doesn't happen you need to give them gentle push.

--
Dalija Prasnikar
Markus Humm

Posts: 5,113
Registered: 11/9/03
Re: A Delphi Developers Guide for 4K Displays [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 25, 2014 1:01 PM   in response to: Dalija Prasnikar in response to: Dalija Prasnikar
Am 25.11.2014 11:11, schrieb Dalija Prasnikar:
Markus Humm wrote:
Am 24.11.2014 20:39, schrieb Dalija Prasnikar:
Markus Humm wrote:
Am 20.11.2014 21:03, schrieb Dalija Prasnikar:
Markus Humm wrote:

And: has anybody already made a QC or QualityPortal request about
natively supporting and handling this new Win 8.1 message? We all could
spare to roll our own solution for this. It would also be nice if the
change I outlined to not accumulating rounding errors could be
incorporated in such a solution.

VCL and FireMonkey lack Per-Monitor DPI support for Windows 8.1
https://quality.embarcadero.com/browse/RSP-9679

There is also report for Delphi IDE high DPI awareness
https://quality.embarcadero.com/browse/RSP-9678

Hello,

I had some private mail conversation with Marco about this topic lately
pointing him to the URL of this tutorial.

He said he had read it and for XE8 some improvements in this area are
being planned or at least looked at which are regarding font sizing and
the IDE would profit from them as well.

Great news.

Yep. ;-) (writing this while installing XE7 update 1 which is great
except the fact that they didn't change status of some QP reports which
were fixed in update 1 to fixed - not sure what the politics about those is)

Changing status of QP reports - there is no policy, you just have to remind them to do so :)

Usually it can take them few days after the release/update to do so on their own, but
if it doesn't happen you need to give them gentle push.

Hello,

this is quite bad as it will lead to even more "trash" in QP than in QC
in no time! They really should adopt one now!

Greetings

Markus
Dalija Prasnikar

Posts: 2,325
Registered: 11/9/99
Re: A Delphi Developers Guide for 4K Displays [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 25, 2014 1:06 PM   in response to: Markus Humm in response to: Markus Humm
Markus Humm wrote:
Am 25.11.2014 11:11, schrieb Dalija Prasnikar:

Changing status of QP reports - there is no policy, you just have to remind them to do so :)

Usually it can take them few days after the release/update to do so on their own, but
if it doesn't happen you need to give them gentle push.

Hello,

this is quite bad as it will lead to even more "trash" in QP than in QC
in no time! They really should adopt one now!

I was referring to QC too, It looks like there is no much difference in way they handle QP and QC.
But it is still too early to tell.

--
Dalija Prasnikar
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02