Using anonymous methods

Top  Previous  Next

New features since Delphi 7 > Anonymous Methods > Using anonymous methods

 

Anonymous methods in Delphi as well as lambda expressions in C++ can be returned by functions and passed to functions as parameters. The following example demonstrates the use as a parameter:

 

 

type

  TFuncOfIntToString = Reference to function(X: Integer): String;

 

procedure AnalyzeFunction(Proc: TFuncOfIntToString);

begin

  Proc(3);

end;

->

 

typedef std::function<System::String (int)> TFuncOfIntToString;

 

 

void AnalyzeFunction(TFuncOfIntToString Proc)

{

  Proc(3);

}

 

 

The use as return value is demonstrated in the next example.

 

 

 

 



This page belongs to the DelphiXE2Cpp11 Documentation

DelphiXE2Cpp11 home  Content