RSS订阅 | 匿名投稿
您的位置:网站首页 > 程序 > 正文

delphi循环遍历同类控件或所有控件

作者:admin 来源: 日期:2011/8/19 9:41:30 人气: 标签:

 

delphi循环遍历同类控件或所有控件

循环遍历同类控件:

 

form1中有groupbox1,内有多个speedbutton,控制其同时按下。

var i:integer;

begin

for i:=0 to form1.groupbox1.controlcount-1 do

if form1.groupbox1.controls[i] is tspeedbutton then

begin

tspeedbutton(form1.groupbox1.controls[i]).allow‍allup:=true;

‍tspeedbutton(form1.groupbox1.controls[i]).groupindex:=i+1;

tspeedbutton(form1.groupbox1.controls[i]).down:=true;

end;

 

结合数据库使用,表示表rz中的rz字段(bit),为1则按下,为0则抬起。

var i:integer;

begin

i:=0;

while not adotable1.eof then

if adotable1.fields[1].asboolen=true then

begin

tspeedbutton(form1.groupbox1.controls[i]).allow‍allup:=true;

‍tspeedbutton(form1.groupbox1.controls[i]).groupindex:=i+1;

tspeedbutton(form1.groupbox1.controls[i]).down:=true;

end

else‍

begin

tspeedbutton(form1.groupbox1.controls[i]).allow‍allup:=true;

‍tspeedbutton(form1.groupbox1.controls[i]).groupindex:=i+1;

tspeedbutton(form1.groupbox1.controls[i]).down:=false;

end;

inc(i);

adotable1.next;

end;

 

遍历Panel组件上的所有控件:

 

procedure frmMain.CLS; //主窗体自定义事件CLS
var i:integer;
begin
  for i:=0 to panel5.ControlCount -1 do
  begin
    if panel5.Controls[i] is TEdit then  //Edit组件
    begin
       ((panel5.Controls[i]) as TEdit).Text:='';
       ((panel5.Controls[i]) as TEdit).Enabled:=true;
    end  else if panel5.Controls[i] is TComboBox then  //ComboBox组件
      begin
         ((panel5.Controls[i]) as TComboBox).Text:='';
         ((panel5.Controls[i]) as TComboBox).Enabled:=true;
      end  else if panel5.Controls[i] is TDateTimePicker then  //DateTimePicker组件
        begin
          ((panel5.Controls[i]) as TDateTimePicker).Enabled:=true;
          ((panel5.Controls[i]) as TDateTimePicker).DateTime:=now();
        end; 
    end;
end;
这个过程主要是清空panel5组件Edit、ComboBox组件Text内容、把DateTimePicker组件日期设为当前日期,并使panel5所有控件可用 ......

读完这篇文章后,您心情如何?
0
0
0
0
0
0
0
0
本文网址: