Click here to Skip to main content
15,798,826 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i do this:

while Form1.Controlcount > 0 do
Form1.Controls[0].Destroy ;

But how to delete only checkboxes?

1 solution

Not only you need to include combo box types, but also the types derived from it, or, more likely, from StdCtrls.TCustomComboBox or, say, StdCtrls.TCustomCombo:[^].

In all cases, you have to check up the instance of your type with operator is
if myControl is StdCtrls.TCustomComboBox then // ... remove the instance

As the deletion is condition, you cannot work with index 0, so you will need to modify your cycle. Appropriate way it to traverse the list of controls in (important!) reverse order. Also, you may need to apply the recursive traversing of the controls.

Note that this is the operation based on dynamic cast approach, where you have to examine the runtime type of the object known by its compile-type type. Not only this can be a bit costly for the performance, it is also considered as violation of general OOP principles. Nevertheless, there are cases when you need to do that.

Share this answer
Maciej Los 23-Nov-14 13:54pm    
Sergey Alexandrovich Kryukov 23-Nov-14 14:00pm    
Thank you, Maciej.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900