0
votes

Applies to XE6, Firemonkey

I am creating a button with an image on it by customizing a TSpeedButton in firemonkey. I am doing this by adding an image to the TSpeedButton in the style editor. The new button works ok. I now want to make another image button so I thought I'd copy and paste the first button on the form. I changed the image in the copied button (via the style editor) and when I hit Apply and Close the new button gets the new image. However I also notice that the original button I copied from also get the new image. So now I have two buttons with the same image. Other than creating a completely new button and adding a new image (which does allow me to have buttons with unique images), is there a way to create buttons that have their own styles using copy/paste?

I noticed this question is related to How to edit a control within a FireMonkey style outside of the style designer? but here I want to do the same thing but from the IDE, not programmatically.

1
I think I figured it out: 1: Create button with image on it; 2) Copy and paste button; 3) In the property editor for the second button, change the name of the StyleLookup name to a new name. That appears to create a new style for the copied button. First time I tried this I got some extra styles in the style editor (with duplicate names) which I couldn't delete or select so I had to delete all the buttons and try again. Unless there is a better answer I will promote this comment to be the answer in 24 hours. - rhody
One problem I noticed with the above approach which negates the whole point of coping a button. When you change the name of the style the button loses all it previous style information, meaning the button has to be designed again. This can't be the way to do it. - rhody
Can't you simply add an image control as a child to the button? The style shouldn't contain the image then. - Uwe Raabe
Using Styles to individualize multiple components of the same type is a really inefficient way of doing things since it was never designed for such a purpose. - Peter
@Rabbe: Do you mean add the child in the style editor or programmatically at runtime? - rhody

1 Answers

6
votes

They exist other approach to this. This is a consumer of resources, but they works as you want.

1 - Drop a TSpeedButton on your Form.

2 - Drop a TImage control on your Form.

3 - With the Structure View (in opposite to the form designer), drop the Image1 component on the SpeedButton1 component, making that TSpeedButton belongs the owner of the Image1.

3 - Now adjust the dimensions of the Image1 to make it the same as the SpeedButton.

4 - On the Structure View, one more time, you must select Image1 and expand it. It appears a MultiResBitMap owned component.

5 - Expand too this component: MultiResBitmap. It appears a TFixedBitmapItem with the name "0 - Normal (1,000).

6 - on the Object Inpector click on the (...) of his property Bitmap.

Now you can copy this structure, based on a Speed button and change the Bitmap of each one!

7 - HINT!!! You must set HitTest of the Image as False, and the same property of the button as True. In other case they is going to seem that the event handler of the SpeedButton don't fires.