Delphi调用爷爷类的方法(重新构造TMethod的data和code部分,其中Code指向祖父类的方法)

时间:2023-03-09 05:49:22
Delphi调用爷爷类的方法(重新构造TMethod的data和code部分,其中Code指向祖父类的方法)

Delphi通过inherited 可以调用父类的方法,但是没有提供直接调用父类的父类的方法(爷爷类),通过变通的方式实现如下:

假设父类是TFather,爷爷类TGrand,调用爷爷类的Write方法:

type
TWriteProc=procedure of Object;
var
WriteProc:TWriteProc;

....
TMethod(WriteProc).Code:=@TGrand.Write;
TMethod(WriteProc).Data:=Self;
WriteProc;
  

http://www.cnblogs.com/hezihang/p/4139656.html