[fpc-pascal] how to use procedure of object in C
Michael Van Canneyt
michael at freepascal.org
Mon Mar 9 18:43:04 CET 2015
On Mon, 9 Mar 2015, OBones wrote:
> Michael Van Canneyt wrote:
>> On Mon, 9 Mar 2015, Xiangrong Fang wrote:
>>> Hi all,
>>> I define a procedure like this:
>>> TDataHandler = procedure(data: Pointer) of object;
>>> procedure SetHandler(h: TDataHandler); external cdecl;
>>> Now, can I implement SetHandler in a library written in C, then call h in
>> IMHO Not without separate assembler code for each CPU.
> How about using TMethod?
> procedure DataHandler(DummySelf: Pointer; data: Pointer);
> // do what you want to do, DummySelf is always nil.
> Method: TMethod;
> Method.Data := nil;
> Method.Code := @DataHandler;
You must be sure that self is passed in the correct register.
I am not sure this is the case if you declare it as an extra argument.
It may be so, but compiler people should confirm this.
I don't think you can take it for granted.
More information about the fpc-pascal