Search code examples
pythonuser-interfacefiremonkey

How do I get a list of all components on a Form in a Python FMX GUI App


I have a DelphiFMX GUI App with a couple of components created on a Form:

self.imgDirt = Image(self)
self.btnLoad = Button(self)
self.btnSave = Button(self)
self.memDirt = Memo(self)
self.lblTitle = Label(self)
self.edtTitle = Edit(self)

How can I get a list of all the components on the Form assuming I didn't know which ones were on the form?


Solution

  • You can simply for-loop through all of the Components on the Form:

    for component in self.Components:
        print(component.ClassName)
    

    You can also do:

       for i in range(0, self.ComponentCount):
            print(self.Components[i].ClassName)
    

    Both code examples would print out:

    TImage
    TButton
    TButton
    TMemo
    TLabel
    TEdit