我们可以这样对form里的控件统一赋值,
for i:=0 to ComponentCount-1 do //此处与下边的都不能用 controlcount
begin
if Components[i] is TEdit then TEdit(Components[i]).Clear;
if Components[i] is TComboBox then TComboBox(Components[i]).Text := '';
if Components[i] is TMemo then TMemo(Components[i]).Clear;
end;
也可以这样对 panel 控件里的多个控件赋值 with Panel1 do
for i:=0 to controlcount-1 do
begin
if controls[i] is TEdit then TEdit(controls[i]).ReadOnly := False;
if controls[i] is TEdit then TEdit(controls[i]).Color := clWhite;
if controls[i] is TComboBox then TComboBox(controls[i]).Enabled := True;
if controls[i] is TComboBox then TComboBox(controls[i]).Color := clWhite;
if controls[i] is Tcheckbox then Tcheckbox(controls[i]).Enabled:= True;
end;可以我就没办法对PageControl页面里的多个TabSheet内的控件赋值了 with PageControl1 do
for i:=0 to controlcount-1 do
begin
if controls[i] is TEdit then TEdit(controls[i]).ReadOnly := False;
if controls[i] is TEdit then TEdit(controls[i]).Color := clWhite;
if controls[i] is TComboBox then TComboBox(controls[i]).Enabled := True;
if controls[i] is TComboBox then TComboBox(controls[i]).Color := clWhite;
if controls[i] is Tcheckbox then Tcheckbox(controls[i]).Enabled:= True;
end;这样写了以后,对TabSheet里的内容没有变化,请问大家这是什么原因呢?
for i:=0 to ComponentCount-1 do //此处与下边的都不能用 controlcount
begin
if Components[i] is TEdit then TEdit(Components[i]).Clear;
if Components[i] is TComboBox then TComboBox(Components[i]).Text := '';
if Components[i] is TMemo then TMemo(Components[i]).Clear;
end;
也可以这样对 panel 控件里的多个控件赋值 with Panel1 do
for i:=0 to controlcount-1 do
begin
if controls[i] is TEdit then TEdit(controls[i]).ReadOnly := False;
if controls[i] is TEdit then TEdit(controls[i]).Color := clWhite;
if controls[i] is TComboBox then TComboBox(controls[i]).Enabled := True;
if controls[i] is TComboBox then TComboBox(controls[i]).Color := clWhite;
if controls[i] is Tcheckbox then Tcheckbox(controls[i]).Enabled:= True;
end;可以我就没办法对PageControl页面里的多个TabSheet内的控件赋值了 with PageControl1 do
for i:=0 to controlcount-1 do
begin
if controls[i] is TEdit then TEdit(controls[i]).ReadOnly := False;
if controls[i] is TEdit then TEdit(controls[i]).Color := clWhite;
if controls[i] is TComboBox then TComboBox(controls[i]).Enabled := True;
if controls[i] is TComboBox then TComboBox(controls[i]).Color := clWhite;
if controls[i] is Tcheckbox then Tcheckbox(controls[i]).Enabled:= True;
end;这样写了以后,对TabSheet里的内容没有变化,请问大家这是什么原因呢?
with PageControl1.Pages[i] do
begin
if Controls[i] is ...
...
end;
for i := 0 to PageControl1.PageCount - 1 do
with PageControl1.Pages[i] do
for j := 0 to ControlCount - 1 do
begin
if Controls[i] is ...
...
end;
错了,应该是:
for i := 0 to PageControl1.PageCount - 1 do
with PageControl1.Pages[i] do
for j := 0 to ControlCount - 1 do
begin
if Controls[j] is ...
...
end;不好意思。
Project 程序名.exe raised exception class ElistError with message 'List index out of bounds (0)'. Process stopped. Use Step or Run to continue.
for i:=0 to controlcount-1 do
begin
if controls[i] is TEdit then TEdit(controls[i]).ReadOnly := False;
if controls[i] is TEdit then TEdit(controls[i]).Color := clWhite;
if controls[i] is TComboBox then TComboBox(controls[i]).Enabled := True;
if controls[i] is TComboBox then TComboBox(controls[i]).Color := clWhite;
if controls[i] is Tcheckbox then Tcheckbox(controls[i]).Enabled:= True;
end; 注:组件不是放到PageControl上的,而是放到PageControl的TTabSheet上的
我弄错了
for i := 0 to PageControl1.PageCount - 1 do
with PageControl1.Pages[i] do
for j := 0 to ControlCount - 1 do
begin
if Controls[j] is ...
...
end;
case pagecontrol1.activepageindex of
0:begin
for i:=0 to controlcount-1 do
begin
if controls[i] is TEdit then TEdit(controls[i]).ReadOnly := False;
if controls[i] is TEdit then TEdit(controls[i]).Color := clWhite;
if controls[i] is TComboBox then TComboBox(controls[i]).Enabled := True;
if controls[i] is TComboBox then TComboBox(controls[i]).Color := clWhite;
if controls[i] is Tcheckbox then Tcheckbox(controls[i]).Enabled:= True;
end;
end;