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

2015-03-10 Thread OBones
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

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

2015-03-10 Thread Jonas Maebe
On 10 Mar 2015, at 10:40, OBones wrote: 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

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

2015-03-10 Thread Michael Schnell
On 03/09/2015 04:20 PM, Xiangrong Fang wrote: can I implement SetHandler in a library written in C, then call h in C? For inter-language calls you obviously need to to define the calling style on both sites. e.g. STDCALL or PASCAL, to make both use compatible calling conventions. I don't

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

2015-03-09 Thread Xiangrong Fang
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? Thankyou. -- Sent from Gmail Mobile

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

2015-03-09 Thread Ewald
On 09 Mar 2015, at 18:43, Michael Van Canneyt wrote: 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 is, as long as the `self` is the first parameter. Same goes for `Class Procedure XXX;` kind of

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

2015-03-09 Thread Michael Van Canneyt
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: type TDataHandler = procedure(data: Pointer) of object; procedure SetHandler(h: TDataHandler); external cdecl; Now, can I implement

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

2015-03-09 Thread Michael Van Canneyt
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

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

2015-03-09 Thread OBones
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

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

2015-03-09 Thread Xiangrong Fang
2015-03-10 0:33 GMT+08:00 OBones obo...@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;