delphi 遍历控件


本文整理自网络,侵删。

 
有10个EDIT控件,取名为EDT1,EDT2,EDT3。。。EDT10,如何用一个循环知道哪个EDIT控件的值是空的?

procedure   TForm1.Button2Click(Sender:   TObject);   
  var   
      I:integer;   
  begin   
      for   i:=0   to   Self.Componentcount-1   do//Self.Componentcount就是TForm1的控件数量   
      begin   
          if   Self.Components[i]   is   TEdit   then     //判断控件是否为TEdit   
          begin   
              if   (Self.Components[i]   as   TEdit).Text=''   then   ShowMessage(Self.Components[i].Name);   
          end;   
      end;   
  end;  
利用这个function   FindComponent(const   Name:   string)函数你可以找到你要的任何控件,然后判断它是否为空. 使用Tedit.findcomponents(edit(I))函数,i为控件的序号,具体看一下帮助!
还有一个方法就是给他们的TAG赋同一个值,比如1,其他默认为零,程序如下:   
  procedure   TForm1.Button2Click(Sender:   TObject);   
  var   
      I:integer;   
  begin   
      for   i:=0   to   Self.Componentcount-1   do//Self.Componentcount就是TForm1的控件数量   
      begin   
          if   Self.Components[i]   is   TEdit   then     //判断控件是否为TEdit   
          begin   
              if   (Self.Components[i]   as   TEdit).Text='')   
                    and   (Self.Components[i]   as   TEdit).tag=1)   then     
                  ShowMessage(Self.Components[i].Name);   
          end;   
      end;   
  end;  

相关阅读 >>

Delphi 结束360safe和360保险箱进程

Delphi程序的exe和dll文件添加版本信息

Delphi 另类计算程序代码运行耗时

Delphi 新增功能之: ioutils 单元(7): tfile 结构的功能

Delphi 动态数组的释放

Delphi检测程序是否在优盘上运行

Delphi中使用isuperobject解析json数据

Delphi 清除ie缓存 internet临时文件 cookie 历史记录 表单记录 上网密码

Delphi int64 与 currency

Delphi7 中tstringlist的delimiter delimitedtext有bug,字符串分割有问题

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...