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

OBones obones at free.fr
Tue Mar 10 10:40:07 CET 2015


Xiangrong Fang wrote:
> 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?
>
It works the same, cast the data you receive to a TMethod and call the 
"code" member with the appropriate parameters. So, in the "C" library do 
this:

typedef struct
{
   Data: Pointer;
   Code: Pointer;
}TMethod;

void SetHandler(TMethod h);
{
   StoredH = h;
}

typedef void (*TDataHandler)(void* Self, void* Data);

void DoSomething();
{
   ((TDataHandler)(StoredH.Code))(StoredH.Data, SomeData);
}

Warning, this is pseudo code, you should adapt it so that it can compile.



More information about the fpc-pascal mailing list