dummzeuch 1517 Posted November 17, 2019 (edited) One frequently asked question that still gets asked today goes like this: “How do I create an array of [component] and fill it with existing [component] instances from the form?” Where [component] usually is TLabel, TCheckbox or TEdit. I’m going to outline some solutions here. Let’s start by defining some parameters: We have got a (VCL) form On that form there are several controls of the same type. Let’s make them CheckBoxes. We want to do something with all these controls In order to make this easier, we want to create an array that contains all these controls So, this is the form: read on in my blog post Edited November 17, 2019 by dummzeuch Share this post Link to post
aehimself 399 Posted November 17, 2019 (edited) I'd add a scrollbox in the groupboxes first, and add insert the controls on the scrollboxes. Just to be sure that they'll be all visible. Edit: Also, I'd add recursivity in the GetAllCheckboxes method, but that's only my taste. Edited November 17, 2019 by aehimself Share this post Link to post
dummzeuch 1517 Posted November 17, 2019 I'm not talking about dynamically adding checkboxes to groupboxes at runtime, but about adding those created in the designer to an array for easier processing. Share this post Link to post
David Heffernan 2353 Posted November 17, 2019 What's wrong with just adding the controls to a collection? Controls.Add(control1); Controls.Add(control2); Etc. 2 Share this post Link to post
Fr0sT.Brutal 900 Posted November 18, 2019 In some places I use such constructions for ctrl in TArray<TControl>.Create(Button1, Checkbox1, Memo1) do ctrl.Enabled := True; 5 Share this post Link to post
M.Joos 30 Posted November 18, 2019 9 hours ago, Fr0sT.Brutal said: In some places I use such constructions for ctrl in TArray<TControl>.Create(Button1, Checkbox1, Memo1) do ctrl.Enabled := True; That's nifty ! I will put that one to my toolbox. Share this post Link to post