![fmxgrid | Embarcadero RAD Studio Delphi C++Builder Blogs](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2020/08/fmx_grid.jpg?resize=1140%2C628&ssl=1)
Author: Jayme Jeffman Filho
You have probably iterated through the Components array many many times as a Delphi developer.
Consider this simple application:
It’s probably no surprise that listing the Components of the form like this…
1 2 3 4 5 6 7 8 9 |
<br> procedure TForm2.Button1Click(Sender: TObject);<br> var<br> i: Integer;<br> begin<br> Memo2.Lines.Clear;<br> for i := 0 to ComponentCount-1 do<br> Memo1.Lines.Add(Components[i].ClassName+' (Name = "'+Components[i].Name+'")')<br> end;<br> |
…gives you the following output, which is very similar to the Structure View in the IDE, except that it doesn’t show the relationships between the components.
Listing the children, and the children of all children (recursively) is simply done by using this procedure:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
<br> procedure TForm2.ListChildren(Obj : TFMXObject; Level : Integer);<br> var<br> i: Integer;<br> begin<br> for i := 0 to Obj.ChildrenCount-1 do begin<br> Memo2.Lines.Add(StringOfChar(' ',2*Level)+<br> Obj.Children[i].ClassName+<br> ' (Name = "'+<br> Obj.Children[i].Name+<br> '")');<br> ListChildren(Obj.Children[i],Level+1);<br> end;<br> end;<br> <br> procedure TForm2.Button2Click(Sender: TObject);<br> begin<br> Memo2.Lines.Clear;<br> ListChildren(Self,0);<br> end;<br> |
The above code will give us a tree output with indentation to show us the children, grandchildren, etc, like this:
The list of children is much longer than you would possibly except at first. We see for instance that in FireMonkey a TButton consists of a TLayout, a TSubImage and a TText. The TSubImage and the TText in turn have 4 animations each to handle hover-in/hover-out and pressing/releasing. Likewise the TMemo holds scrollbars, a popup context menu, and much more.
The entire output from ListChildren follows below:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
TSubImage (Name = "")<br> TButton (Name = "Button1")<br> TLayout (Name = "")<br> TSubImage (Name = "")<br> TRectAnimation (Name = "")<br> TRectAnimation (Name = "")<br> TRectAnimation (Name = "")<br> TRectAnimation (Name = "")<br> TText (Name = "")<br> TColorAnimation (Name = "")<br> TColorAnimation (Name = "")<br> TColorAnimation (Name = "")<br> TColorAnimation (Name = "")<br> TMemo (Name = "Memo1")<br> TLayout (Name = "")<br> TSubImage (Name = "")<br> TRectAnimation (Name = "")<br> TLayout (Name = "")<br> TSmallScrollBar (Name = "")<br> TSmallScrollBar (Name = "")<br> TScrollBar (Name = "")<br> TScrollBar (Name = "")<br> TBrushObject (Name = "")<br> TBrushObject (Name = "")<br> TFontObject (Name = "")<br> TScrollContent (Name = "")<br> TPopupMenu (Name = "")<br> TPopupMenuContent (Name = "")<br> TMenuItem (Name = "")<br> TMenuItemContent (Name = "")<br> TMenuItem (Name = "")<br> TMenuItemContent (Name = "")<br> TMenuItem (Name = "")<br> TMenuItemContent (Name = "")<br> TMenuItem (Name = "")<br> TMenuItemContent (Name = "")<br> TMenuItem (Name = "")<br> TMenuItemContent (Name = "")<br> TMenuItem (Name = "")<br> TMenuItemContent (Name = "")<br> TEdit (Name = "Edit2")<br> TLayout (Name = "")<br> TSubImage (Name = "")<br> TRectAnimation (Name = "")<br> TLayout (Name = "")<br> TLayout (Name = "")<br> TBrushObject (Name = "")<br> TBrushObject (Name = "")<br> TFontObject (Name = "")<br> TPopupMenu (Name = "")<br> TPopupMenuContent (Name = "")<br> TMenuItem (Name = "")<br> TMenuItemContent (Name = "")<br> TMenuItem (Name = "")<br> TMenuItemContent (Name = "")<br> TMenuItem (Name = "")<br> TMenuItemContent (Name = "")<br> TMenuItem (Name = "")<br> TMenuItemContent (Name = "")<br> TMenuItem (Name = "")<br> TMenuItemContent (Name = "")<br> TMenuItem (Name = "")<br> TMenuItemContent (Name = "")<br> TContentEdit (Name = "")<br> TClearEditButton (Name = "ClearEditButton1")<br> TLayout (Name = "")<br> TSubImage (Name = "")<br> TRectAnimation (Name = "")<br> TRectAnimation (Name = "")<br> TRectAnimation (Name = "")<br> TSubImage (Name = "")<br> TRectAnimation (Name = "")<br> TRectAnimation (Name = "")<br> TRectAnimation (Name = "")<br> TButton (Name = "Button2")<br> TLayout (Name = "")<br> TSubImage (Name = "")<br> TRectAnimation (Name = "")<br> TRectAnimation (Name = "")<br> TRectAnimation (Name = "")<br> TRectAnimation (Name = "")<br> TText (Name = "")<br> TColorAnimation (Name = "")<br> TColorAnimation (Name = "")<br> TColorAnimation (Name = "")<br> TColorAnimation (Name = "")<br> TViewport3D (Name = "Viewport3D1")<br> TDummy (Name = "")<br> TDummy (Name = "")<br> TCamera (Name = "")<br> TSphere (Name = "Sphere1")<br> TCube (Name = "Cube1")<br> TTextureMaterialSource (Name = "TextureMaterialSource1") |
Enjoy!
Design. Code. Compile. Deploy.
Start Free Trial Upgrade Today
Free Delphi Community Edition Free C++Builder Community Edition