delphi循环遍历同类控件或所有控件
2011-03-27 07:11
661 查看
循环遍历同类控件:
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]).allowallup:=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]).allowallup:=true;
tspeedbutton(form1.groupbox1.controls[i]).groupindex:=i+1;
tspeedbutton(form1.groupbox1.controls[i]).down:=true;
end
else
begin
tspeedbutton(form1.groupbox1.controls[i]).allowallup:=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所有控件可用 ......
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]).allowallup:=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]).allowallup:=true;
tspeedbutton(form1.groupbox1.controls[i]).groupindex:=i+1;
tspeedbutton(form1.groupbox1.controls[i]).down:=true;
end
else
begin
tspeedbutton(form1.groupbox1.controls[i]).allowallup:=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所有控件可用 ......
相关文章推荐
- c# winform 循环遍历界面上的所有控件,foreach,Controls,AllowDrop
- Delphi遍历所有控件
- 循环遍历获取窗体或页面所有同类型的控件
- c# winform 循环遍历界面上的所有控件,foreach,Controls,AllowDrop
- c# winform 循环遍历界面上的所有控件
- Winform循环遍历界面上的所有控件 foreach,controls,allowdrop
- 循环遍历控件
- 遍历页面上所有的TextBox控件并赋值
- WPF 遍历DataTemplate(获取所有控件)
- DELPHI中怎么在程序中遍历上面的全部控件
- Oracle 函数 “申请通过后,将该表中循环遍历到的所有内容插到另一个表中”
- c# 中循环遍历所有文件夹下的文件
- .net下遍历内容页所有控件实现重置功能
- 关于类的入门例子(8): 遍历窗体中所有控件的函数
- 遍历页面所有控件(原)
- asp.net遍历页面所有的按钮(或控件)
- 通过游标循环遍历表所有字段
- delphi 文件搜索,遍历所有子目录
- 如何遍历一个程序中的所有控件
- PHP遍历循环列出目录下所有的FLV文件