Setting Firemonkey control font programmatically in C++

1k views Asked by At

I have a custom Firemonkey control that extends TEdit which is dynamically created on a form. I am attempting to set it's font size when it is created using:

Search->Font->Size = 15;

However, the font remains unchanged on the control.

I have another control of the same type that is already on the form which I can change the font size programmatically. I noticed with this control, that if the Size setting is set to false in the StyledSettings properties I can change the font, whereas if the Size setting is set to true, I cannot change the font size.

So, when I create my custom control, I am trying to programmatically set the Size property to false, however I cannot figure out how to do so.

I have tried:

Search->StyledSettings.Size = false;

and

Search->StyledSettings = ListBox->StyledSettings - [TStyledSetting.ssSize];

neither of which will even compile. How can I make sure this property is removed on my custom control at run time? Or is there another way I should be setting its font?

1

There are 1 answers

1
Remy Lebeau On BEST ANSWER

However, the font remains unchanged on the control.

I have another control of the same type that is already on the form which I can change the font size programmatically. I noticed with this control, that if the Size setting is set to false in the StyledSettings properties I can change the font, whereas if the Size setting is set to true, I cannot change the font size.

This is documented behavior:

Using the StyledSettings Property

When changing text representation properties of the TTextSettings type objects, remember that when you are changing the value of a property (of the TextSettings.Font.Size property in the previous example), then the actual changing of the object's view happens only if the ITextSettings.StyledSettings property does not contain the TStyledSetting.Size constant. The "Relation between TStyledSetting constants and TTextSettings properties" table shows which TStyledSetting constants control handling of the TTextSettings text representation properties.

FMX.Graphics.ITextSettings

Remember that when you are changing the value of a property (for example of the TextSettings.FontColor property), then the actual changing of the control's view happens only if the StyledSettings property does not contain the TStyledSetting.FontColor constant. The following table shows which TStyledSetting constants control handling of which TTextSettings text representation properties.

Relation between TStyledSetting constants and TTextSettings properties

TStyledSetting   Dependent TTextSettings   Meaning 
   Constant             Properties

Family           TFont.Family              Font name. 
Size             TFont.Size                Font size. 
Style            TFont.Style               Font style (italic, bold). 
FontColor        FontColor                 Font color. 
Other            HorzAlign, VertAlign,     How to align and show the text.  
                 Trimming, and WordWrap.

So, when I create my custom control, I am trying to programmatically set the Size property to false, however I cannot figure out how to do so.

The correct syntax in C++ is:

Search->StyledSettings = Search->StyledSettings >> TStyledSetting::Size;