C++ Builder 2009 Iterate/Recurse through Components on a Form

159 Views Asked by At

I wish to iterate/recurse through the components on a form.

I plan on iterating/recursing through the components to make bulk changes to a components of a particular type, but in order to do so, I need a handle to all components.

I checked Code Complete and Google but did not have any luck answering my own question.

1

There are 1 best solutions below

0
On

Use the TWinControl.Controls[] property, eg:

Procedure DoSomething(AControl: TWinControl);
Var
  I: Integer;
  Ctrl: TControl;
Begin
  If AControl is TSomeControl then
  Begin
    ...
  End;
  For I := 0 to AControl.ControlCount-1 do
  Begin
    Ctrl := AControl.Controls[I];
    If Ctrl is TWinControl then
      DoSomething(TWinControl(Ctrl));
  End; 
End;

Procedure TMyForm.DoIt;
Begin
  DoSomething(Self);
End;