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

posted @ 2017-05-14 23:36  findumars  Views(565)  Comments(0Edit  收藏  举报