[fpc-pascal] how to use procedure of object in C

Xiangrong Fang xrfang at gmail.com
Mon Mar 9 23:34:09 CET 2015

2015-03-10 0:33 GMT+08:00 OBones <obones at free.fr>:

> 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;

​I'm not sure how this works, but it seems that you are deliberately
converting a normal procedure to a method. What I want is exactly opposite
- I want to convert a method to a normal procedure.

If I define the interfact of DataHandler like this:

​TDataHandler = procedure(data: Pointer); cdecl;

It is very easy to use in an so, no matter it is written in C or pascal.

But the problem is, I want to do this:


where h is a METHOD, not a normal procedure​.

Because I want to use the handler wrapped in my Class.

However, like in my first mail, if I define THandler a procedure of object,
it makes easier to SetHandler(AMethod); but how can I use that "procedure
of object" pointer in the so?


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20150310/0cfbadcf/attachment.html>

More information about the fpc-pascal mailing list