我想给一组的panel赋color值,但一个一个赋值实在没效率,可是就是找不到像vb那样的控件数组,有什么解决办法吗?

解决方案 »

  1.   

    没有不过delphi中相似的组件有共同的父类类如:
    你可以检索form中所有的按钮,然后类型上溯,调用相关方法1
      

  2.   

    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;