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 检查ip地址合法性

Delphi monthoftheyear、weekoftheyear、weekofthemonth、dayoftheyear … 相对时间

Delphi清空回收站

Delphi 在win32程序中显示dos调试窗口

Delphi twebbrowser 获取cookie

Delphi 删除任意文件的任意位置的任意数量的字符

Delphi中emptyparam参数被改写问题

Delphi 注入win7的单元

Delphi获取flash文件的影片时长,原始尺寸,帧数等信息

Delphi controlcount和componentcount的区别

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



打赏

取消

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

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

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

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

评论

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