Delphi调用爷爷类的方法(自己构建一个procedure of Object)

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

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

1
2
3
4
5
6
7
8
9
type
  TWriteProc=procedure of Object;
var
  WriteProc:TWriteProc;
 
....
  TMethod(WriteProc).Code:=@TGrand.Write;
  TMethod(WriteProc).Data:=Self;
  WriteProc;

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

posted @ 2019-09-24 17:00  findumars  Views(306)  Comments(0Edit  收藏  举报