Delphi 是通过接口的一个 Invoke(…) 函数来实现匿名函数的,举例:
interface
type
TFilterPredicate = reference to function(const Path: string;const SearchRec: TSearchRec): Boolean;
// ...
class function GetFiles(const Path: string;
const Predicate: TFilterPredicate): TStringDynArray;overload; inline; static;
C++ Builder 对应写为:
typedef System::DelphiInterface<TFilterPredicate> _di_TFilterPredicate;
__interface TFilterPredicate : public System::IInterface
{
virtual bool __fastcall Invoke(const System::UnicodeString Path, const System::Sysutils::TSearchRec &SearchRec) = 0 ;
};
// ..
static System::TStringDynArray __fastcall GetFiles(const System::UnicodeString Path, const _di_TFilterPredicate Predicate)/* overload */;
现在的问题是:在C++ Builder XE8 里怎样使用 _di_TFilterPredicate ?
(备注:C++ Builder XE8不支持 Lamda 表达式)