I'm attempting to translate a small library that was written by a coworker in C# into Delphi.

I'm attempting to translate a small library that was written by a coworker in C# into Delphi. It relies heavily on generics and anonymous methods.

I'm having issues attempting to pass an anonymous function as an argument to a procedure. I have code that looks like:

procedure TSomeObject.SomeProc(callback: TFunc);

The code that calls this procedure looks like:

someObject.SomeProc(
  function(in: string):Integer
  begin
    if Assigned(in) then
      Result := 1;
  end);

But the compiler just gives me:
 E2010 Incompatible types: 'System.SysUtils.TFunc>' and 'Procedure'

I've tried adding explicit type parameters. I've tried making the anonymous method an ordinary method and a stand alone function. Still get the same error message just a different type for the second operand. When I made it an object method it said the second type was 'Procedure of object' instead.

Anyone have a clue what I'm doing wrong?

Comments