Anonymous method as function result
Posted
by iamjoosy
on Stack Overflow
See other posts from Stack Overflow
or by iamjoosy
Published on 2010-05-07T12:15:16Z
Indexed on
2010/05/07
12:18 UTC
Read the original article
Hit count: 225
delphi
|anonymous-methods
What I want to do is to assign an anonymous method which I get as a function result to a variable of the same type. Delphi complains about not beeing able to do the assignement. Obviously Delphi things I want to assign the "GetListener" function instead of the result of that same function. Any help with this is very much appreciated.
type
TPropertyChangedListener = reference to procedure (Sender: TStimulus);
TMyClass = class
function GetListener:TPropertyChangedListener
end;
....
var MyClass: TMyClass;
Listener: TPropertyChangedListener;
begin
MyClass:= TMyClass.create;
Listener:= MyClass.GetListener; // Delphi compile error: E2010 Incompatible types: TPropertyChangedListener' and 'Procedure of object'
end;
© Stack Overflow or respective owner