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 ... end;
procedure TFoo.MyProc(X, Y: Integer); begin ... 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;
->
public delegate void TMyProc<T>(T Param); public delegate void TMyProc2<Y>(Y Param1, Y Param2);
private class TFoo : TObject {
public void Test() { TMyProc<int> X = null; TMyProc2<int> Y = null; X = Sample; X(10); Y = MyProc; Y(20, 30); }
public void MyProc(int X, int Y) { ... }
public TFoo() {} };
public static void Sample(int Param) { ... }
public static void Test() { TFoo F = null; F = new TFoo(); F.Test(); F = null; }
|
This page belongs to the Delphi2C# Documentation |
Delphi2C# home Content |