With the release of C++Builder XE8 and RAD Studio XE8, we have made it even easier for C++ developers to work wth Delphi’s anonymous methods and generics. We have updated the recommended way to handle Delphi anonymous methods in your C++ applications. The revised description, in How to Handle Delphi Anonymous Methods in C++, uses either a Functor (function object) or a Lambda expression. See the code examples on the following RAD Studio XE8 DocWiki pages.
How to Handle Delphi Anonymous Methods in C++ – http://docwiki.embarcadero.com/RADStudio/XE8/en/How_to_Handle_Delphi_Anonymous_Methods_in_C%2B%2B
How to Handle Delphi Generics in C++ – http://docwiki.embarcadero.com/RADStudio/XE8/en/How_to_Handle_Delphi_Generics_in_C%2B%2B
You can also use a lambda wherever an API expects an anonymous method. The DelphiInterface class has been updated to auto-convert to a lambda. This feature can only be used with the Clang-based C++ Compilers. The following example C++ code illustrates use of a lambda.
#include <System.hpp>
#include <System.IOUtils.hpp>
#include <iostream>
int main()
{
String ext(“.cpp”);
TStringDynArray files = TDirectory::GetFiles(TDirectory::GetCurrentDirectory(),
[ext](const String Path, const System::Sysutils::TSearchRec &SearchRec) -> bool
{
return ExtractFileExt(SearchRec.Name) == ext;
});
std::cout << “Found ” << files.Length
<< ” files with ext: ‘” << AnsiString(ext).c_str() << “‘n”;
for (int i=0; i<files.Length; ++i)
std::cout << AnsiString(files[i]).c_str() << std::endl;
}
Share This | Email this page to a friend