[fpc-pascal] how to use procedure of object in C
OBones
obones at free.fr
Mon Mar 9 17:33:19 CET 2015
Michael Van Canneyt wrote:
>
>
> On Mon, 9 Mar 2015, Xiangrong Fang wrote:
>
>> Hi all,
>> I define a procedure like this:
>>
>> type
>> 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 C?
>
> IMHO Not without separate assembler code for each CPU.
>
> Michael.
How about using TMethod?
procedure DataHandler(DummySelf: Pointer; data: Pointer);
begin
// do what you want to do, DummySelf is always nil.
end;
var
Method: TMethod;
begin
Method.Data := nil;
Method.Code := @DataHandler;
SetHandler(TDataHandler(Method));
end;
More information about the fpc-pascal
mailing list