Jump to content
Primož Gabrijelčič

redefined anonymous method - bug or my mistake?

Recommended Posts

Hi all,


Somehow I think that the following code should compile, but it does not. It looks like the compiler uses the wrong `TCallback` definition when resolving the property. Am I correct or did I miss something and I'm just stupid?


program Project184;


{$R *.res}


  TCallback = reference to procedure (value: int64);

  TRunner = class
  public type
    TCallback = reference to procedure;
  strict private
    FOnCallback: TCallback;
    procedure Run;
    property OnCallback: TCallback read FOnCallback write FOnCallback;

procedure TRunner.Run;
  OnCallback(); // <-- E2035 Not enough actual parameters


Delphi 10.3.1, in case this is a regression bug.

Share this post

Link to post

Well, TRunner.TCallback is closer in scope, so I would expect the compiler to use it instead of the global TCallback, so that does look like a bug. Should be easy enough to work around, though, just specify TRunner.TCallback as type for the property and its field.


Of course it's a bit problematic to have this kind of nameing conflict in the first place, not (only) for the compiler but also for a programmer trying to make sense of the code 😉.


Delphi 10.3 Version 26.0.33219.4899 still shows this behaviour, by the way.

  • Like 1

Share this post

Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now