• 遍历窗口中的控件


    【对象引用】

      对象的名称仅仅只代表一个指向对象实体的引用而不代表对象实体

    obj := M1.create;

    FreeAndNil(obj);

      Delphi 提供了两个专用的操作符: as 及 is 操作符,它们分别用于对象的转型及对象
    的类型判断。

    is 操作符用于在程序运行期间检查一个对象引用所指的对象实体的具体类型。

    as 操作符用于将某个特定类型的对象引用转为其它类型的对象引用。简单说来, as 用
    于将某个类的对象转换成其它类的对象

    **************************************************************

    有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;

    原文链接:http://www.cnblogs.com/bytutu/archive/2012/09/21/2697082.html

  • 相关阅读:
    VS2010-MFC(对话框:模态对话框及其弹出过程)
    VS2010-MFC(对话框:设置对话框控件的Tab顺序)
    VS2010-MFC(对话框:为控件添加消息处理函数)
    VS2010-MFC(对话框:创建对话框类和添加控件变量)
    manacher算法模板
    [洛谷P1017] 进制转换
    [洛谷P1126] 机器人搬重物
    [洛谷P1032] 字串变换
    [POI2005]SAM-Toy Cars
    [洛谷P1528] 切蛋糕
  • 原文地址:https://www.cnblogs.com/zhrong/p/5670770.html
Copyright © 2020-2023  润新知