Jump to content
Sonjli

Passing an anonymous function

Recommended Posts

Hello,

I don't know how I can pass an anonymous function inside a omniTask.

Example:

 

type
	TMyObject = class
    	[...]
    end;
	
    TMyFunction = reference to function(const Arg1: string): TMyObject;
    
var
	lFunc: TMyFunction;
    
procedure Something;
begin
	lFunc := function(const Arg1: string): TMyObject
    begin
    	result := TMyObject.Create(Arg1);
    end;
    
	CreateTask(
    procedure(Task: IOmniTask)
    var
    	lthdFunc: TMyFunction;
        lResult: TMyObject;
    begin
    	lthdFunc := Task.Params['MyRefFunction'].As???; // <-- What here?
        lResult := lthdFunc('dummy');
    	[...]
    end
    )
    .SetParameter('MyRefFunction', lFunc)
    .Run;
end;

Thanks in advance,

Eddy.

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
×