现在我要建立一个新的控件,要求它的属性中有Parameters这个属性,现在在建立过程中有这样一个问题,就是创建这个属性,Parameters:=TParameters.create(AOwner: TPersistent; ItemClass: TCollectionItemClass),这其中两个参数我应该怎么写。

解决方案 »

  1.   

    第一个参数传从TPersistent继承下来的类,一般传self就可以。
    第二个参数传从TCollectionItemClass继承下来的类或它的子类。
      

  2.   

    更正:第一个参数传self就可以,就是你自己定义的那个控件的类
      

  3.   

    TCollectionItemClass = class of TCollectionItem;
    这个是定义,你从TCollectionItem继承自己的类。你看看ADODB.pas的
    FParameters := TParameters.Create(Self, TParameter);TParameter = class(TCollectionItem)
      

  4.   

    TParameter = class(TCollectionItem)中TCollectionItem怎么去写啊
      

  5.   

    如果不自己写,直接把TParameter传进去也可以。
    Parameters := TParameters.Create(Self, TParameter);
      

  6.   

    我这个控件是继承TSpeedButton类的,只是想有一个Parameters属性。
      TDyHotQry = class(TSpeedButton)
      private
        FParameters : TParameters;
           ...
      protected
      public
        constructor Create(AOwner : TComponent); override;
           ...
      published
        property Parameters : TParameters read FParameters write SetParamsList;
           ...
      end;
    constructor TDyHotQry.Create(AOwner : TComponent);
    begin
       inherited Create(AOwner);
       Glyph.LoadFromResourceName(HInstance,'TDyHOTQRY');
           ...
       FParameters   := TParameters.Create(a1,a2); {输入/输出参数}
           ...
    end;就是上面的a1,a2两个参数该怎么写。我乱写了很多,都不行,这是怎么回事呢
      

  7.   

    unit Unit2;interfaceuses   Classes, ADODB,Buttons;
    type
      TDyHotQry = class(TSpeedButton)
      private
        FParameters : TParameters;
        procedure SetParamsList(const Value: TParameters);
      protected
      public
        constructor Create(AOwner : TComponent); override;
      published
        property Parameters : TParameters read FParameters write SetParamsList;
      end;implementation{ TDyHotQry }constructor TDyHotQry.Create(AOwner: TComponent);
    begin
      inherited;
      FParameters   := TParameters.Create(self,TParameter); {输入/输出参数}
    end;procedure TDyHotQry.SetParamsList(const Value: TParameters);
    begin
      FParameters := Value;
    end;end.没问题啊。
      

  8.   

    unit Unit2;interfaceuses   Classes, ADODB,Buttons;
    type
      TDyHotQry = class(TSpeedButton)
      private
        FParameters : TParameters;
        procedure SetParamsList(const Value: TParameters);
      protected
      public
        constructor Create(AOwner : TComponent); override;
      published
        property Parameters : TParameters read FParameters write SetParamsList;
      end;implementation{ TDyHotQry }constructor TDyHotQry.Create(AOwner: TComponent);
    begin
      inherited;
      FParameters   := TParameters.Create(self,TParameter); {输入/输出参数}
    end;procedure TDyHotQry.SetParamsList(const Value: TParameters);
    begin
      FParameters := Value;
    end;end.没问题啊。
      

  9.   

    同上所说,我是生成了控件,但怎么样也不能用这个控件,提示错误“Access violation at address O8F3A466 in mould "控件源代码.bpl"
      

  10.   

    提示错误“invalid class typecast ”