[fpc-pascal] Class procedural type
Sven Barth
pascaldragon at googlemail.com
Tue Dec 18 06:42:44 CET 2012
Am 17.12.2012 22:27 schrieb "Ewald" <ewald at yellowcouch.org>:
>
>
> On 17 Dec 2012, at 20:04, Sven Barth wrote:
>
> >
> > There is no real solution for this.
>
> I already thought so, I thank you for clearing this matter up to me.
>
> >
> >> Any ideas?
> >>
> >> BTW: For time being I fixed it through
> >> TProcType(Pointer(@TTestClass.AMethod)), where `TProcType =
Procedure;`.
> >> I think this boiles down to the same as a class procedure is nothing
> >> more than a normal procedure as I see it (except for the name and some
> >> other syntax)
> >>
> >
> > This is not correct. A class method without static still has a hidden
parameter through which the class type is passed.
>
> Ah, this is interesting. I didn't know of this hidden parameter, but now
that you mention it, it makes sense. So if I declare the method as
> Class Procedure AMethod; static;
>
> It should not contain this hidden parameter? In that case the above code
(with the intermediate pointer cast) would prove correct? (of course it is
no cross platform solution or anything, but that is besides the matter now)
It would be a cross plattform solution, because the method pointer will
just be a Pointer insteat of a TMethod record.
>
>
> > If you want to use the above you need to declare your method as
"static;". In that case a method will behave the same as a normal procedure
variable, but if you want to change e.g. class properties or class
variables of the class the method belongs to, you must use the class name
(e.g. TMyClass.MyProperty) to access it.
>
> So if I get you right, the use of `static` after a method make the hidden
class type parameter disappear, but also mandates use of the class name
every time I want to use the class' [static fields / class properties /
class methods]?
>
Not quite, see Paul's mail. Sorry for the confusion :)
> Suppose TTestClass contains `AField: Integer; static;`, then the
following would be right if I understand you correctly?
>
> Class Procedure TTestClass.AMethod; static; // I don't know if `static`
should be in the implementation as well, but I'll soon figure out :-)
It's enough to have it in the declaration.
Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20121218/d2b84882/attachment.html>
More information about the fpc-pascal
mailing list