[fpc-pascal] "class" methods for objects
Michael Van Canneyt
michael at freepascal.org
Fri Jul 16 10:48:19 CEST 2010
It exists already, but is called 'static'
program testso;
Type
MyObject = Object
procedure MySomething; static;
end;
Procedure MyObject.MySomething;
begin
Writeln('OK');
end;
Var
O : MyObject;
begin
O.MySomething;
end.
Michael.
On Fri, 16 Jul 2010, Helmut Hartl wrote:
> Hello,
>
> while converting bullet physic code to native fpc, i would find it handy
> to have something like "class" methods for objects. (Methods without self
> pointer)
> (It would enhance the readability of the code much, because I were not
> forced to
> move such c++ class functions to global functions)
> Reading doc and wiki I found nothing similar.
>
> A simple test of the below showed test code gives me the following
> impression.
> a) It's not fully implemented
> b) It's not handled right in the compiler
> (the code should not compile if the second writeln is commented)
> c) It has to be used differently.
>
> Thanks for comments,
>
> helmut
>
> ----snip
> program Project1;
>
> type
> TestObject=object
> class function StaticFunction:boolean;
> end;
>
> class function TestObject.StaticFunction: boolean;
> begin
> result:=true;
> end;
>
> var o:TestObject;
>
> begin
> writeln(o.StaticFunction);
> writeln(TestObject.StaticFunction); //(22,21) Error: Only static variables
> can be used in static methods or outside methods
> end.
> ---snap
>
> _______________________________________________
> fpc-pascal maillist - fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>
More information about the fpc-pascal
mailing list