1
votes

In this scenario, I created a default button on my FireMonkey HD application via RADStudio XE2. I then created a custom style for the button, named "Style1". This style is very much similar to the default button style, however, it has a TImage control next to the TText control.

In simple words, a button with an image next to the text.

Now, I'll apply an image to the TImage control for the button? Because if I apply an image to the TImage control VIA the style designer, the other controls who use the style will also get the same image.

2

2 Answers

3
votes

you can do it at runtime. at first you have to name your TImage style object, for ex. 'btnimg' after that you can find it by name using FindStyleResource:

procedure LoadImage(btn : TButton; imgFileName : string);
var img : TImage;
begin
    img := btn.FindStyleResource('btnimg') as TImage;

    if not assigned(img) then exit;

    img.bitmap.LoadFromFile(imgFileName); 
end;
1
votes

You might be interested in my TBitmapSpeedButton control, which has this functionality ready-rolled: http://monkeystyler.com/blog/entry/my-first-firemonkey-custom-control-tbitmapspeedbutton plus the update to load the image from a style resource: http://monkeystyler.com/blog/entry/tbitmapspeedbutton-loading-images-from-the-style