[fpc-pascal] Method pointer to a static method of an object?
Michael Van Canneyt
michael at freepascal.org
Wed Jul 28 19:41:17 CEST 2010
On Wed, 28 Jul 2010, Jetcheng Chu wrote:
> Hi,
>
> I want to make a reference to a static method of an object, but keep
> getting error messages.
>
> ================================================================
> program StaticMethodPtr;
>
> {$MODE objfpc}{$STATIC ON}
>
> type
> MyMethod = procedure (A: Integer) of object;
>
> MyObject = object
> procedure Test(A: Integer); static;
> end;
>
> procedure MyObject.Test(A: Integer);
> begin
> Writeln(A);
> end;
>
> var
> Ob: MyObject;
> M: MyMethod;
>
> begin
> M := @MyObject.Test;
> { ^ Error: Incompatible types: got "<address of
> procedure(LongInt) of object;Register>" expected
> "<procedure variable type of procedure(LongInt)
> of object;Register>" }
> M := @Ob.Test;
> { ^ Incompatible types: got "STATICMETHODPTR.
> <procedure variable type of procedure(LongInt)
> of object;Register>" expected "STATICMETHODPTR.
> <procedure variable type of procedure(LongInt)
> of object;Register>" }
> end.
> ================================================================
>
> Is this a bug or an expected behavior?
It is expected behaviour. "Procedure of object" only works with classes,
and only with real methods, not with class methods.
Michael.
More information about the fpc-pascal
mailing list