delphi中,遍历窗体上的控件,并显示在ListBox1中:
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('文本框值:'+Tedit(GroupBox1.Controls[i]).text);
end;
ListBox1.Items.Add('遍历控件结束******');
end;
Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号
执行时间: 0.046436071395874 seconds