TBase = class public Method; virtual; end;TA = class(TBase) public Method; override; end;TB = class(TA) public Method; override; end;implementationTB.Method; begin inherited inherited Method; // 不能这样调用祖父类的方法,有什么办法可以实现? end;
TBase = class public Method; virtual;dynamic; end;TA = class(TBase) public Method; override;dynamic; end;TB = class(TA) public Method; override;dynamic; end;
public Method; virtual;
end;TA = class(TBase)
public Method; override;
end;TB = class(TA)
public Method; override;
end;implementationTB.Method;
begin
inherited inherited Method; // 不能这样调用祖父类的方法,有什么办法可以实现?
end;
public Method; virtual;dynamic;
end;TA = class(TBase)
public Method; override;dynamic;
end;TB = class(TA)
public Method; override;dynamic;
end;
晕,有你这样设计的么????开眼界了
是我从别人那里继承的,没办法!
调用方法和以前一样。
怎么个一样法,说说看?
begin
inherited inherited Method; // 不能这样调用祖父类的方法,有什么办法可以实现?
end;
--------------
修改为
TB.Method;
var baseInstance :TBase;
begin
baseInstance := TBase.Create;
baseInstance.Method;
end;
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type a = class
public
procedure show;virtual;
end;
b = class(a)
public
procedure show;
end;
c = class(b)
public
procedure show;
end;type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
procedure showMsg(p: A);
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}{ a }procedure a.show;
begin
Showmessage('a.show');
end;{ b }procedure b.show;
begin
Showmessage('b.show');
end;{ c }procedure c.show;
{var
aInstance : a;}
begin
{ aInstance:= a.Create;
aInstance.show;}
showmessage('c');
end;
procedure TForm1.showMsg(p:A);
begin
p.show;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
cInstance : c;
begin
cInstance := c.Create;
showMsg(cInstance);//这句执行的结果,显示的是a.show.
end;end.
var
cInstance : c;
这个是必须要创建的,不然如何调用方法?
你用我第二种方法不就可以吗?没有什么临时变量.
var
cInstance : c;
这个是必须要创建的,不然如何调用方法?
你的程序本身就是有缺欠的,而且和我所说的东西关系不大,我是说实现类似
inherited inherited Method;
的调用。