FMX Font Size Tip

The inspiration for this tip comes from a developer on the Delphi Developer FB Group. Thank you! Please see his excellent post here for more information.

By default, Delphi will set your font size to 12. When your application starts, it will read the system settings and automatically adjust all font sized 12 to the system scale settings. However, none of the other font sizes are scaled. You need to do this programmatically. I typically use a factory method on my Frames to control this. Here is an example:

  frame.lblText.Font.Size     := Fonts.Sub1;
  frame.lblQuestion.Font.Size := Fonts.Sub2;

Remember to update the SyledSettings for Size so it doesn’t inherit properties:

You can also do this programatically:

lblQuestion.StyledSettings := lblQuestion.StyledSettings - [TStyledSetting.Size];

The Fonts unit looks like this:

The code to calculate the FontSizes:

And the code to obtain the Font Scaling System Setting:

One thing I love about Delphi is that it is multi-paradigm, it doesn’t force you into an OOP framework. So it’s trivial to add wrapper functions like this:

I hope this tip helps.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s