Click here to Skip to main content
15,880,392 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?
Posted

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:
http://docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/HelpUpdate2/EN/html/delphivclwin32/StdCtrls_TComboBox.html[^].

In all cases, you have to check up the instance of your type with operator is
Delphi
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.

—SA
 
Share this answer
 
v2
Comments
Maciej Los 23-Nov-14 13:54pm    
+5
Sergey Alexandrovich Kryukov 23-Nov-14 14:00pm    
Thank you, Maciej.
—SA

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