[fpc-pascal]Passing Methods as Callback Procedures?
Jon David Sawyer
badquanta6384 at comcast.net
Mon Dec 16 21:23:34 CET 2002
On Mon, 2002-12-16 at 18:38, Judison wrote:
> 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)
Its in the docs ^_^ I dunno why you don't have it ^_^
>
> >
> > 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));
Procedure ForEach(Callback: Procedure(Item: Pointer));
>
> 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
FPC Compiles without complaints.. It doesn't even warn me that I'm
intermixing Procedures of Object and Procedures; I had assumed this
meant that it would work. I'm also using FPC Devel 1.1.
As a fix I just created my own object that inherited from tCollection
and accepted Procedure or Object as a callback. ^_^ It worked.. I just
think the compiler should warn/fault on you if you make that kind of
mistake ^_^
>
> _______________________________________________
> fpc-pascal maillist - fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
More information about the fpc-pascal
mailing list