Use as events |
Top Previous Next |
New features since Delphi 7 > Anonymous Methods > Use as events
Method reference types can be used as a kind of event in Delphi and become std::function's by translation to C++.
type TAnProc = Reference to procedure;
TAn4Component = class(TComponent) private FMyEvent: TAnProc; public property MyEvent: TAnProc Read FMyEvent Write FMyEvent; end;
procedure TestAnonymous4; var C : TAn4Component; begin C := TAn4Component.Create; C.MyEvent := procedure begin ; end; end;
->
typedef std::function<void ()> TAnProc;
class TAn4Component : public System::TComponent { typedef System::TObject inherited; private: TAnProc FMyEvent; public: /*property MyEvent : TAnProc read FMyEvent write FMyEvent;*/ TAnProc ReadPropertyMyEvent() { return FMyEvent;} void WritePropertyMyEvent(TAnProc Value){FMyEvent = Value;} public: TAn4Component() {}
};
void TestAnonymous4() { TAn4Component* C = nullptr; C = new TAn4Component(); C->WritePropertyMyEvent([&]() -> void { ; }); }
|
This page belongs to the DelphiXE2Cpp11 Documentation |
DelphiXE2Cpp11 home Content |