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?

Mailing lists / fpc-pascal / 2014-02
5 messages · 4 people ·
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
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?
In our previous episode, Mark Morgan Lloyd said:
tobject(tmethod(func).data)
A nice one from the 'Dirty tricks' section :)
It might be better to change the WriteBuff to accept an object in that case...
Michael.
[GRIN] Yes, very much agreed that it could do with an extra parameter. But I'm trying to limit the changes that I'm making to the original (Javascript) code, because it's a big job and it's going to help enormously if I can knock something together afterwards which can do a line-by-line comparison of the original and transcribed files.
In our previous episode, Mark Morgan Lloyd said: 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.