How to get/create anonymous method from TRttiMethod?
- by Heinrich Ulbricht
I want to handle a TRttiMethod as anonymous method. How could I do this?
Here is a simplified example of how I wish things to work:
Interface:
TMyClass = class
public
// this method will be acquired via Rtti
procedure Foo;
// this method shall return above Foo as anonymous method
function GetMethodAsAnonymous: TProc;
end;
Implementation:
function TMyClass.GetMethodAsAnonymous: TProc;
var
Ctx: TRttiContext;
RttiType: TRttiType;
RttiMethod: TRttiMethod;
begin
Ctx := TRttiContext.Create;
try
RttiType := Ctx.GetType(Self.ClassType);
RttiMethod := RttiType.GetMethod('Foo');
Result := ??????; // <-- I want to put RttiMethod here - but how?
finally
Ctx.Free;
end;
end;