如何在运行时删除表单中的所有复选框 [英] How to delete all checkboxes in my form at runtime

查看:83
本文介绍了如何在运行时删除表单中的所有复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我这样做:



而Form1.Controlcount> 0做

Form1.Controls [0] .Destroy;



但是如何只删除复选框?

i do this:

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

But how to delete only checkboxes?

推荐答案

您不仅需要包含组合框类型,还需要包含从中派生的类型,或者更可能来自 StdCtrls.TCustomComboBox 或,比方说, StdCtrls.TCustomCombo

http://docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/HelpUpdate2/EN/html/delphivclwin32/StdCtrls_TComboBox.html [ ^ ]。



在所有情况下,您必须使用运营商检查您的类型实例是

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
if myControl is StdCtrls.TCustomComboBox then // ... remove the instance



由于删除是条件,因此您无法使用索引0,因此您需要修改周期。以适当的方式遍历(重要!)逆序的控件列表。此外,您可能需要应用控件的递归遍历。



请注意,这是基于动态强制转换方法的操作,您必须检查运行时类型编译类型所知的对象。不仅这对于性能来说可能有点贵,它也被认为违反了一般的OOP原则。不过,有些情况下你需要这样做。



-SA


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


这篇关于如何在运行时删除表单中的所有复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆