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.
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;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.