如何批量更改控件属性,在线等。。。。

老子 2006-08-12 06:41:00
偶是这样写的,:
for I := 0 to ControlCount -1 do
begin
if (Controls[I] is TEdit) then
(controls[i] as TEdit).Enabled := enable;
if (controls[i] is TMemo) then
(controls[i] as TMemo).Enabled := enable;
if (controls[I] is TComboBox) then
(Controls[i] as TComboBox).Enabled := enable;
if (controls[i] is TCheckBox) then
(controls[I] as TCheckBox).Enabled := enable;
if (controls[i] is TRadioGroup) then
(controls[i] as TRadioGroup).Enabled := enable;
if (controls[i] is TDateTimePicker) then
(controls[i] as TDateTimePicker).Enabled := enable;
end;
咋就不起作用呢????????
...全文
221 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
老子 2006-08-12
  • 打赏
  • 举报
回复
成功,给分,
老子 2006-08-12
  • 打赏
  • 举报
回复
多谢啦,等我试试,成功就给分
王集鹄 2006-08-12
  • 打赏
  • 举报
回复
for I := 0 to ComponentCount -1 do
begin
if (Components[I] is TEdit) then
(Components[I] as TEdit).Enabled := enable;
if (Components[I] is TMemo) then
(Components[I] as TMemo).Enabled := enable;
if (Components[I] is TComboBox) then
(Components[I] as TComboBox).Enabled := enable;
if (Components[I] is TCheckBox) then
(Components[I] as TCheckBox).Enabled := enable;
if (Components[I] is TRadioGroup) then
(Components[I] as TRadioGroup).Enabled := enable;
if (Components[I] is TDateTimePicker) then
(Components[I] as TDateTimePicker).Enabled := enable;
end;

Controls是访问放在Form上的控件,如果控件不是直接放在Form上就访问不了
可以用Components处理
wudi_1982 2006-08-12
  • 打赏
  • 举报
回复
如果你想加入关于类型的判断,用下面代码,
procedure TForm1.FormCreate(Sender: TObject);
var
i : integer;
begin
for I := 0 to ControlCount -1 do
begin

if (Controls[i].ClassNameIs('tedit')) then
Controls[i].Enabled := false;
if (Controls[i].ClassNameIs('TMemo')) then
Controls[i].Enabled := false;
if (Controls[i].ClassNameIs('Tbutton')) then
Controls[i].Enabled := false;

end;
end;
wudi_1982 2006-08-12
  • 打赏
  • 举报
回复
procedure TForm1.FormCreate(Sender: TObject);
var
i : integer;
begin
for I := 0 to ControlCount -1 do
begin
Controls[i].Enabled := false;

end;
end;

5,392

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧