How do I determine the "z-index" of a Firemonkey component that I have used SendToBack or BringToFront methods on?

71 views Asked by At

I have tested putting components on a standard FMX form (TForm) and viewing this form as text. It seems the IDE is automatically putting the components in the correct rendering order to get the order of components correct. If I am dynamically creating components and re-ordering them (TRectangle, TEllipse), I'd like to know how to determine their "z-index" for rendering them or recreating them from disk again. I have looked things like ComponentIndex but this does not change when I apply SendToBack and BringToFront to a component.

1

There are 1 answers

3
Andre Van Zuydam On

Edit: After some fiddling and checking the results I have managed to determine that TFMXObject has an Index property. (Thanks to @Tom for pointing this out). I can use this to determine the "z-index" of a dynamically created component. I am using the latest version of RAD Studio.

AComponent := TEllipse.Create(Self);
AComponent.Parent := Self;
AComponent.Position.X := 0;
AComponent.Position.Y := 0;
AComponent.Width := 100;
AComponent.Height := 100;

AComponent.Index := 5; //This is the magic bit 

Simply storing and setting the Index property after creating the components dynamically restores their proper order on the form or layout.