[fpc-pascal]Passing Methods as Callback Procedures?
Judison
jueca at brturbo.com
Mon Dec 16 19:38:12 CET 2002
Hi,
On Sun, 15 Dec 2002 15:32:43 +0000
Jon David Sawyer <badquanta6384 at comcast.net> wrote:
> Ok, I've got some code that looks like this:
>
> fCollection.ForEach(@Self.DoEach);
fCollection is a TCollection?
My TCollection does not have ForEach ;) (1.1 CVS 2002/12/13)
>
> Now when DoEach() is called its Self and the Self above
> are not the same...
>
> Is this supposed to happen?
>
It depends on ForEach declaration.
if it is something like this:
procedure ForEach(CallBack: procedure(x: integer));
I really don't know if FPC will compile it, as your DoEach is a method (procedure of object)
I hope you's ForEach declaration is something like:
procedure ForEach(CallBack: procedure(x:integer) of object);
Normally you have a Type
type
TForEachCallBackProc = procedure(x: integer) of object;
a type "procedure" is just a pointer to de procedure, a "procedure of object" is (I Think) a record, with a pointer to a procedure and other to the context (Self).... (I don't know exactly how OO works in FPC)
I hope this can help you
Your Friend,
Judison
More information about the fpc-pascal
mailing list