編譯器通過是這樣的.
B = class(A)
private
constructor Create(AOwner: TComponent);
end;
如果A或者A的祖先也有一個一個構造函數而且B能夠繼承(public,protected),
當你使用B.Create(..)的時候,實際上調用的是和B血緣關係最近的Create;
而B的Create沒有被調用.
第一和第二都是這樣.
b.op;調用的還是A.oP;
我這裡有個簡單的例子.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses Unit2;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
Form2:=TForm2.Create(Application);
Form2.Show;
Form2.f;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Application.CreateForm(TForm3, Form3);
Form3.Show;
Form3.f;
end;
end.
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type
TForm2 = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
procedure f;
end;
TForm3=class(TForm2)
private
procedure f;
public
//procedure f;
end;
var
Form2: TForm2;
Form3: TForm3;
implementation
{$R *.dfm}
procedure TForm3.f;
begin
Caption:='TForm3.f';
end;
procedure TForm2.f;
begin
Caption:='TForm2.f';
end;
end.
program Project1;
uses
Forms,
Unit1 in 'Unit1.pas' {Form1},
Unit2 in 'Unit2.pas' {Form2};
{$R *.res}
begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.