BCB : how to iterate over controls on a form?

后端 未结 3 1046
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-17 07:23

I am looking for some BCB code to iterate over the controls on a form and get some information about them.

I tried using myForm->ControlCount and

3条回答
  •  没有蜡笔的小新
    2020-12-17 07:55

    Here it is:

    void EnumerateAll(TComponent *container)
    {
       // Enumarate its children
       for (int i = 0; i < container->ComponentCount; i++)
          {
          // extract the control at index i
          TComponent *child = container->Components[i];
    
          if ( child->InheritsFrom (__classid(TComponent)) )    //this check is optional
             Form3->Memo->Lines->Add(child->Name);
          }
    }
    

    Usage:

    EnumerateAll(MyForm);
    

    The function above will enumerate also the menu items.
    Also see: C++ builder - enumerate components on TPanel

    Here are more details about the VCL hierarchy: http://docwiki.embarcadero.com/RADStudio/Tokyo/en/Class_library

提交回复
热议问题