Procedural types |
Top Previous Next |
New features since Delphi 7 > Generics > Procedural types
The procedure type and the method pointer can be declared with type parameters. Parameter types and result types can also use type parameters.
type TMyProc<T> = procedure(Param: T); TMyProc2<Y> = procedure(Param1, Param2: Y) of object; type TFoo = class procedure Test; procedure MyProc(X, Y: Integer); end;
procedure sample(Param: Integer); begin WriteLn(Param); end;
procedure TFoo.MyProc(X, Y: Integer); begin WriteLn('X:', X, ', Y:', Y); end;
procedure TFoo.Test; var X: TMyProc<Integer>; Y: TMyProc2<Integer>; begin X := sample; X(10); Y := MyProc; Y(20, 30); end;
procedure Test; var F: TFoo; begin F := TFoo.Create; F.Test; F.Free; end;
->
template<typename T> using TMyProc = std::function<void (T)>; template<typename Y> using TMyProc2 = std::function<void (Y, Y)>; //--------------------------------------------------------------------------- class TFoo : public System::TObject { typedef System::TObject inherited; public: void Test(); void MyProc(int X, int Y); public: TFoo() {} System::TClass ClassType() const; };
//--------------------------------------------------------------------------- void sample(int Param) { WriteLn(Param); } //--------------------------------------------------------------------------- void TFoo::MyProc(int X, int Y) { { Write(L"X:"); Write(X); Write(L", Y:"); WriteLn(Y); }; } //--------------------------------------------------------------------------- void TFoo::Test() { TMyProc<int> X; TMyProc2<int> Y; X = sample; X(10); Y = std::bind(&TFoo::MyProc, this, std::placeholders::_1, std::placeholders::_2); Y(20, 30); }
|
This page belongs to the Delphi2Cpp Documentation |
Delphi2Cpp home Content |