Am 17.12.2012 22:27 schrieb "Ewald" <ew...@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
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to