3

How can you set a TLabel to Bold and back to normal runtime in Delphi XE8 firemonkey multi device project?

I've tried this but it doesn't work:

label.TextSettings.Font.Style := [TFontStyle.fsBold];

Also tried:

label.Font.Style := [TFontStyle.fsBold];
Remi
  • 1,289
  • 1
  • 18
  • 52

2 Answers2

6

Set label.StyledSettings.Style false, then it will follow the Fontstyle settings.

enter image description here

Here a sample code to toggle StyledSettings.Stylewith in code (although I don't remember that I've ever played back and forth with these. For me it's more a one time setup at start).

procedure TForm6.Button9Click(Sender: TObject);
begin
  if TStyledSetting.Style in Label3.StyledSettings then
    Label3.StyledSettings := Label3.StyledSettings - [TStyledSetting.Style]
  else
    Label3.StyledSettings := Label3.StyledSettings + [TStyledSetting.Style]
end;

And to toggle the TextSettings.Font.Style

procedure TForm6.Button8Click(Sender: TObject);
begin
  if TFontStyle.fsBold in Label3.TextSettings.Font.Style then
    Label3.TextSettings.Font.Style := Label3.TextSettings.Font.Style - [TFontStyle.fsBold]
  else
    Label3.TextSettings.Font.Style := Label3.TextSettings.Font.Style + [TFontStyle.fsBold];
end;
Tom Brunberg
  • 20,312
  • 8
  • 37
  • 54
  • This isn't possible. Can only change label.styledsettings and not styledsettings.style – Remi May 04 '15 at 13:32
  • I can't check with XE8 right now. Do you mean that the Object Inspector doesn't show you the `StyledSettings` in XE8? – Tom Brunberg May 04 '15 at 13:43
  • Ow yes it shows in object inspector but i wanted to do it runtime. But thanks that works only how i do change the text to normal again after changing it to bold? – Remi May 04 '15 at 13:48
  • What you can do in design-time can also be done in run-time. Changing it back works the same way. – Jerry Dodge May 04 '15 at 13:55
1

Try this:

Label1.Font.Style := [fsBold];

I used delphi 10.4.

fcdt
  • 2,371
  • 5
  • 14
  • 26