Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2014-02

Getting info on a procedure parameter

5 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Mark Morgan Lloyd

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?

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Marco van de Voort
to Mark Morgan Lloyd

In our previous episode, Mark Morgan Lloyd said:

Show quoted text 5 lines
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)

Reply by email

Michael Van Canneyt
to Marco van de Voort
Marco van de Voort wrote 8 lines
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)

A nice one from the 'Dirty tricks' section :)
It might be better to change the WriteBuff to accept an object in that case...

Michael.

Reply by email

Mark Morgan Lloyd
to Michael Van Canneyt
Michael Van Canneyt wrote 14 lines
On Tue, 11 Feb 2014, Marco van de Voort 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) A nice one from the 'Dirty tricks' section :) It might be better to change the WriteBuff to accept an object in that case...

[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.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Constantine Yannakopoulos
to Marco van de Voort: In our previous episode, Mark Morgan Lloyd said: tobject(tmethod(func).data)
Marco van de Voort wrote 9 lines
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.

Reply by email