Reputation: 370
I created a style like this:
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?
Upvotes: 1
Views: 2455
Reputation: 1218
Here is an example how I do it with ListBox Item
vItem.StylesData['descript'] := 'Description';
vItem.StylesData['details'] := 'Details text';
vItem.ImageIndex := 3;
In my case "descript" and "details" are TText. you can change names in StyleName property (in styles).
To change the image simply by specifying an image index for the ListBox Item (vItem.ImageIndex) in my example, the TGlyph image in style should have the name 'glyphstyle'.
// how to access to component in style:
vItem.NeedStyleLookup;
vItem.ApplyStyleLookup; // without this, FindStyleResource will return nil
vSwitch := vItem.FindStyleResource('switch') as TSwitch;
Assert(vSwitch <> nil);
vSwitch.IsChecked := vCampaign.Enable;
vSwitch.OnClick := DoOnClickSwitch;
Upvotes: 1
Reputation: 154
Upvotes: 2