I've implemented this kind of thing once via FPC. The basic idea is that you patch a VMT entry of the instantiated class. Code goes like this:
You could find my solution at http://www.linderdaum.com in old downloadsCode:Function tObjectsLinker.IntroduceVMT(VMT:Pointer):String; Var ParentVMT:Pointer; ParentClass:tLClass; Begin While Assigned(VMT) Do Begin ParentVMT:=tClass(VMT).ClassParent; If Not Assigned(ParentVMT) Then Exit; If FindClass(tStaticClass(ParentVMT).ClassName,ParentClass) Then Begin If ParentClass.PackageID=CORE_PACKAGE Then Begin Logger.Log('Class '+tStaticClass(VMT).ClassName+' expands '+ParentClass.ClassName); pPointer(VMT+vmtParent)^:=ParentClass.StaticClass; // do injection Exit(ParentClass.ClassName); End; End; VMT:=tClass(VMT).ClassParent; End; Logger.Fatal('Unable to determine class ancestor'); End; Procedure tObjectsLinker.IntroduceClass(Var LClass:tLClass); Var ParentVMT:Pointer; // VMT:Pointer; // ParentClass:tLClass; Begin If LClass.PackageID=CORE_PACKAGE Then Begin // don't touch Core classes // FIXME: ParentVMT:=LClass.StaticClass.ClassParent; If Assigned(ParentVMT) Then LClass.ExpandsClass:=tStaticClass(ParentVMT).ClassName Else LClass.ExpandsClass:=''; Exit; End; LClass.ExpandsClass:=IntroduceVMT(LClass.StaticClass); End;
Bookmarks