|
Anonymous Methods |
Top Previous Next |
|
New features since Delphi 7 > Anonymous Methods Delphi anonymous methods are declared using the keyword reference to. They represent closures: callable values that may capture variables from their surrounding scope. Unlike method pointers, anonymous methods are not bound to an object instance and do not use the Code + Data method pointer representation.
Anonymous methods are commonly used for:
In the current automatic translation, anonymous methods are represented as callable C++ objects (lambdas or wrapper types).
Depending on the translation mode:
1 Declaring Anonymous Method Types
Delphi
type TProcRef = reference to procedure; TFuncRef = reference to function(X: Integer): Integer;
C++ portable
typedef d2c::callback<void()>; TProcRef typedef d2c::callback<int (int)>;TFuncRef
C++Builder
typedef System::Sysutils::_di_TProc TProcRef; typedef System::Sysutils::_di_TFunc__2<int,int> TFuncRef;
The generated type is a callable object that can store lambdas, free functions, or wrapped methods.
Anonymous Method Type Identity
Delphi
Distinct named reference to types are treated as different types, even if their signatures are identical.
C++
Distinct Delphi types are translated into distinct C++ typedefs or wrapper types, preserving type identity where possible and allowing overload resolution to match Delphi behavior.
Known Limitations related to anonymous methods
|
|
This page belongs to the Delphi2Cpp Documentation |
Delphi2Cpp home Content |