On 17.12.2012 17:39, Ewald wrote:
Hello,
Is there any way to define the appropriate type for `AMethod` (in mode
ObjFPC)?
TTestClass = Class
Public
Class Procedure AMethod;
End;
I tried
Type TSomeType = Class Procedure;
But this didn't work. Rather obvious of course since this could also be
interpreted as a class named `Procedure` [I think].
Also I tried
Type TSomeType = Class Procedure of Object;
But this didn't get me any further. I read the manual (section 3.6 --
http://www.freepascal.org/docs-html/ref/refse17.html) and it contains no
data in respect to this little problem of mine.
There is no real solution for this.
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. 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.
Regards,
Sven
_______________________________________________
fpc-pascal maillist - fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal