Search code examples
delphifiremonkeydelphi-10.1-berlin

delphi How to change at runtime a firemonkey user style text sub-property


I created a style like this:

enter image description here

Then I create a TLayout inherited component named TLieu

My goal is to instantiate it at runtime and change: Image property, Title.Text property, Informations.Text property, Map, Infos, Link buttons

My code, but it's not working:

Procedure TF_Main.Button1Click(Sender: TObject);
var
  Lieu: TLieu;
begin
  Lieu := TLieu.Create(VSB_Place);
  Lieu.Name := 'Test';
  Lieu.StyleName := 'Lieu';
  Lieu.StylesData['Title.Text'] := 'My Title';
  // TLayout(Lieu).StylesData['Title.Text'] := 'My Title';  // this doesn't work either
end;

How can I change the sub properties of a custom user styled component at runtime?


Solution

    1. TLieu must be inherited from TStyledControl
    2. Use Lieu.StyleLookup instead of Lieu.StyleName
    3. Before change StyleData call ApplyStyleLookup