[fpc-pascal] Method pointer to a static method of an object?

Jetcheng Chu jcchu at acm.org
Wed Jul 28 16:58:23 CEST 2010


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?

--
Jetcheng Chu
http://people.rerouted.org/jcchu



More information about the fpc-pascal mailing list