0

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.

halfer
  • 19,824
  • 17
  • 99
  • 186
James Oravec
  • 19,579
  • 27
  • 94
  • 160
  • possible duplicate of [Is there any way to get all the controls on a container control?](http://stackoverflow.com/questions/414928/is-there-any-way-to-get-all-the-controls-on-a-container-control) – David Dec 16 '13 at 13:36

1 Answers1

0

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;
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770