覆盖一个类的Create的方法(扩展了Create方法的参数),编译是有警告是否正常?如何避免?例如有如下申明,我的Create的方法实现是否正确?type
  TMyLabel = class(TLabel)
  private
    { Private declarations }
  public
    { Public declarations }
    constructor Create(AOwner:TComponent;const ICaption:String);
    //destructor Destroy; override;
  end;implementationconstructor TWord.Create(AOwner: TComponent; const ICaption: String);
begin
  //inherited TLabel.Create(AOwner);
  TLabel.Create(AOwner);
end;end.

解决方案 »

  1.   

    constructor Create(AOwner:TComponent;const ICaption:String); reintroduce;
    好像就没有警告了//这个好像不对,改为
    constructor TWord.Create(AOwner: TComponent; const ICaption: String);
    begin
      inherited Create(AOwner);
      ...
    end;
      

  2.   

    Create 是类方法,应该不能覆盖呀
    你只要重新定义就可以了呀
    比如说下面这个例子
    Type   
       TMyFamily=Class
       Private
            FMyFatherName:String;
            FMyMotherName:String;
           ...
       Public
           Constructor Create(StrFatherName,StrMontherName:String);
           ...
       End;创建对象
    MyFamilyObject:=TMyFamily.Create('zhang','Li');
      

  3.   

    type  T1 = class(TObject)
        procedure Test(I: Integer); overload; virtual;
      end;
      T2 = class(T1)
        procedure Test(S: string); reintroduce; overload;
      end;
      

  4.   

    用inherited Create(AOwner);就对了
    你试试
      

  5.   

    问题是我就想从一个类继承,比如说TLable,但是我有想把TLable的Create(构造函数)改为可以接受更多参数的形势,这时候不能使用override关键字,如果不使用有不能使用inherited 关键字了,另外我想请问reintroduce是干什么用的?
      

  6.   

    用reintroduce也可用inherited关键字
    reintroduce可覆盖继承的虚方法--Use reintroduce when you want to hide an inherited virtual method with a new one.
      

  7.   

    reintroduce是让系统不报出hide的这个warning。
    mastering delphi 6上有一个这方面的例子的,
    unit ReintrF;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls;type
      TMyClass = class
        procedure One; overload; virtual;
        procedure One (I: Integer); overload;
      end;  TMySubClass = class (TMyClass)
        procedure One; overload; override;
        procedure One (S: string); reintroduce; overload;
      end;  TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.DFM}{ MyClass }procedure TMyClass.One;
    begin
      ShowMessage ('MyClass.One');
    end;procedure TMyClass.One(I: Integer);
    begin
      ShowMessage ('Integer: ' + IntToStr (I));
    end;{ MySubClass }procedure TMySubClass.One;
    begin
      ShowMessage ('MySubClass.One');
    end;procedure TMySubClass.One(S: string);
    begin
      ShowMessage ('String: ' + S);
    end;procedure TForm1.Button1Click(Sender: TObject);
    var
      Obj: TMySubClass;
    begin
      Obj := TMySubClass.Create;
      Obj.One;
      Obj.One (10);
      Obj.One ('Hello');
      Obj.Free;
    end;end.