如果类不从别的类继承(实际上也就是从TObject继承),
constructor Create
virtual
//virtual表示虚函数,表示可以被子类override;
destructor Destory: virtual;
如果从其它类继承,如:TForm
constructor Create(AOwner: TComponent)
override;
destructor Destory: override;
如果子类想再overload一个函数,则必须加上reintroduce和overload
constructor Create(AOwner: TComponent)
overload
override
//这里的overload必面在override之前.
constructor Create(AOwner: TComponent
AParent: TWinControl)
reintroduce
overload;
例子
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type
Ta = class(TObject)
public
constructor Create
virtual;
destructor Destory
virtual;
procedure aaa
virtual;
end;
tb = class(ta)
public
constructor Create
overload
override;
constructor Create(a: String)
reintroduce
overload;
destructor Destory
override;
procedure aaa
overload
override;
procedure aaa(a: string)
reintroduce
overload;
end;
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
c: tb;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
constructor ta.Create;
begin
end;
procedure ta.aaa;
begin
end;
destructor ta.Destory;
begin
end;
constructor tb.Create;
begin
inherited;
end;
constructor tb.Create(a: String);
begin
inherited create;
end;
destructor tb.Destory;
begin
inherited;
end;
procedure tb.aaa;
begin
inherited;
end;
procedure tb.aaa(a: String);
begin
inherited aaa;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
c:= tb.Create('aaa');
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
c.Free;
end;
end.