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.
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to