[fpc-pascal] Getting info on a procedure parameter
Constantine Yannakopoulos
alfasud.ti at gmail.com
Tue Feb 11 17:16:39 CET 2014
On Tue, Feb 11, 2014 at 4:52 PM, Marco van de Voort <marcov at stack.nl> wrote:
> In our previous episode, Mark Morgan Lloyd said:
> > If a method a.WriteBuff() is passed another method b.finish() as a
> > parameter, can it access b before calling finish(), or would this
> > require an explicit parameter?
> >
> > If yes, how?
>
> tobject(tmethod(func).data)
>
One word of caution though: Not sure about FPC but in Delphi a caller may
pass a class method instead of an instance method to a method variable. In
this case the correct typecast would be:
T
Class(tmethod(func).data)
and AFAIK there is no safe way to test if the bare pointer TMethod.Data
points to an instance or a class VMT in order to do the correct cast
without AVs. Jedi code library (JCL) has an IsObject() and an IsClass()
function but I have found them not to be fullproof and can raise AVs as
well.
Maybe the OP could consider using interfaces instead of method variables.
--
Constantine.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20140211/0a6f3fa0/attachment.html>
More information about the fpc-pascal
mailing list