Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2010-07

Method pointer to a static method of an object?

3 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Jetcheng Chu

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?

Reply by email

Michael Van Canneyt
to Jetcheng Chu
Jetcheng Chu wrote 42 lines
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.

Reply by email

Graeme Geldenhuys
to Michael Van Canneyt

Op 2010-07-28 19:41, Michael Van Canneyt het geskryf:

It is expected behaviour. "Procedure of object" only works with classes, and only with real methods, not with class methods.

Then should the "procedure of object" syntax change to become "procedure of class" - to be less ambiguous? :)

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://opensoft.homeip.net/fpgui/

Reply by email