Is there an easy way to loop through an array of controls (user specified, not every control on the form) and disable them?

At the moment I'm just disable/enabling them one by one e.g.

ctrl1.enabled := false;
ctrl2.enabled := false;
ctrl22.enabled := false;


Is there a way to pass, either to a function or otherwise to disable an array of them so it could be done in significantly less lines? The code's a bit ugly the way it is at the moment.

Thanks in advance for any solutions.

8 Years
Discussion Span
Last Post by LizR

Thats not an array of controls, thats just a bunch of controls with similar name.

You can use the findcomponentbyname so you could then use a for loop (assuming you do have all 1..22)


Hi, yeah I didn't mean actually an array of created controls, I meant you supply an array of the names of the components on the form (they're not called "1...22" there's lots of different names that was just intended to show there's lots of them :p)

Is there a way in delphi to have like a unlimited parameter procedure? So I could pass in like

disableControls('name1', 'name2', 'name3', ...);

Sorry for the stupid questions I'm not very familiar with Delphi, I know the above would be quite easy in other languages though

Thanks again.

edit; Nevermind, Done it. Thanks!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.