用什么方法可以一次清空一个Form里面所有的域

bingor 2002-12-19 03:25:46
比如我的一个Form里面有很多的TEdit和一些TCombobox.如何在一个click事件中一次把所有的输入内容清空呢?
 望指教
...全文
41 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
bingor 2002-12-19
  • 打赏
  • 举报
回复
我的组件是在容器里。

谢谢kingfish.还想问一下如果想清stringgrid是不是方法一样呢

woainihaha 2002-12-19
  • 打赏
  • 举报
回复
同意kingfish(八百里秦川@龙城异客)最后一次的代码.
liuxingstar 2002-12-19
  • 打赏
  • 举报
回复
for(int i=0;i<this->ComponentCount;i++)//遍历所有控件
{
TEdit *btn=dynamic_cast<TEdit*>(Components[i]);//判断为TEdit类
btn->Text=""; //清空

}
kingfish 2002-12-19
  • 打赏
  • 举报
回复
for( int i = 0 ;i<ComponentCount ;i++){
AnsiString Type = Components[i]->ClassName() ;
if(Type.AnsiCompareIC("TComboBox")==0){
TComboBox *cb = dynamic_cast<TComboBox *>(Components[i]);
if(cb) cb->Clear();
}
if(Type.AnsiCompareIC("TEdit")==0){
TEdit *ed = dynamic_cast<TEdit *>(Components[i]);
if(ed) ed->Text="";
}
}
keenleung 2002-12-19
  • 打赏
  • 举报
回复
估计你这些控件都是放在容器里的
kingfish 2002-12-19
  • 打赏
  • 举报
回复
for(int i=0;i<Form1->ComponentCount;i++)
{
if(Form1->Components[i]->ClassNameIs("TComboBox"))
{
TComboBox *cb = dynamic_cast<TComboBox*>(Form1->Controls[i]);
cb->Items->Clear();
cb->ItemIndex = -1;
}
if(Form1->Components[i]->ClassNameIs("TEdit"))
{
TEdit *et = dynamic_cast<TEdit*>(Form1->Controls[i]);
et->Text="";
}
}
bingor 2002-12-19
  • 打赏
  • 举报
回复
出现问题,没有清值!
keenleung 2002-12-19
  • 打赏
  • 举报
回复

for(int i=0;i<Form1->ComponentCount;i++)
换成
for(int i=0;i<Form1->ControlCount;i++)
试试
bingor 2002-12-19
  • 打赏
  • 举报
回复
编译通过,但click时报
Project demo.exe raised exception class ElistError with message 'List index out of bounds(4)'.Process stopped. Use Step or Run to continue.
bingor 2002-12-19
  • 打赏
  • 举报
回复
不好意思没看见上面的。我试试
bingor 2002-12-19
  • 打赏
  • 举报
回复
能不能详细说明,谢谢
kingfish 2002-12-19
  • 打赏
  • 举报
回复
void __fastcall TForm1::Button3Click(TObject *Sender)
{
for(int i=0;i<Form1->ComponentCount;i++)
{
if(Form1->Controls[i]->ClassNameIs("TComboBox"))
{
TComboBox *cb = dynamic_cast<TComboBox*>(Form1->Controls[i]);
cb->Items->Clear();
cb->ItemIndex = -1;
}
if(Form1->Controls[i]->ClassNameIs("TEdit"))
{
TEdit *et = dynamic_cast<TEdit*>(Form1->Controls[i]);
et->Text="";
}
}
}
kingfish 2002-12-19
  • 打赏
  • 举报
回复
遍历一遍窗口上控件,如果是Edit或ComboBox就清空

13,824

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧