That instancePtr is puzzling for now. Just pointer.
Consider this:
Code:
type
TMyClass = class
function MyMethod(): boolean;
end;
But inside MyMethod implementation, you have access to automatically added variables Result and Self. Result is what received the function result while Self is the class instance from which this method was called:
Code:
var
MyInstance: TMyClass;
b: boolean;
...
b:= MyInstance.MyMethod;
..but where does Self come from?
It's not magic, it's not rocket science. Any class method is in fact a regular procedure/function with one hidden "Self" parameter in its parameter list. Both Pascal and C++, could be boiled to
Code:
function MyClass_MyMethod(Self: TMyClass): boolean;
Edit: virtual methods are the same it's the process of *calling* them that is more tricky.
In this form you can *export* it from, say, your DLL, C-style. I'm sure *lots* of windows API functions that require you first get a handle to object then pass that handle to various other functions, may very well be constructor and class methods in disguise. Because THandle is ptruint, a pointer-sized unsigned integer.
Things like TMyClass are typed pointers as well.
Bookmarks