for i:=0 to self.componentcount-1 do if self.components[i] is TPanel then begin (Self.Components[i] as TPanel).Color:=clRed; end; Self的意思在Form上 是本Form,如果在写控件的时候就是本控件。 如果你的代码直接写到Form中,则可以不用Self for i:=0 to self.componentcount-1 do if components[i] is TPanel then begin (Components[i] as TPanel).Color:=clRed; end;
你可以检索form中所有的按钮,然后类型上溯,调用相关方法1
if self.components[i] is TPanel then
begin
(Self.Components[i] as TPanel).Color:=clRed;
end;
Self的意思在Form上 是本Form,如果在写控件的时候就是本控件。
如果你的代码直接写到Form中,则可以不用Self
for i:=0 to self.componentcount-1 do
if components[i] is TPanel then
begin
(Components[i] as TPanel).Color:=clRed;
end;