delphi控件遍历

来源:互联网 发布:软件测试工作职责 编辑:程序博客网 时间:2024/04/29 22:21

 procedure TForm1.Button1Click(Sender: TObject);
var
          i:Integer;
begin
          ListBox1.Items.Clear;
          ListBox1.Items.Add('开始遍历控件******');
          for i:=1 to ComponentCount-1 do
          begin
            ListBox1.Items.Add(Components[i].Name);
            if Components[i] is TDateTimePicker then
              ListBox1.Items.Add('时间控件值:' + DateToStr(TDateTimePicker(Components[i]).Date));
            if Components[i] is Tedit then
              ListBox1.Items.Add('文本框值:'+Tedit(Components[i]).text);
          end;
          ListBox1.Items.Add('遍历控件结束******');
end;

遍历GroupBox1中的子控件
procedure TForm1.Button2Click(Sender: TObject);
var
          i:Integer;
begin
          ListBox1.Items.Clear;
          ListBox1.Items.Add('开始遍历控件******');
          for i:=1 to GroupBox1.ControlCount-1 do
          begin
            ListBox1.Items.Add(GroupBox1.Controls[i].Name);
            if GroupBox1.Controls[i] is TDateTimePicker then
              ListBox1.Items.Add('时间控件值:' + DateToStr(TDateTimePicker(GroupBox1.Controls[i]).Date));
            if GroupBox1.Controls[i] is Tedit then
              ListBox1.Items.Add('文本框值:'+TGedit(GroupBox1.Controls[i]).text);
          end;
          ListBox1.Items.Add('遍历控件结束******');
end;

原创粉丝点击