Base types |
Top Previous Next |
New features since Delphi 7 > Generics > Base types
The base type of a parameterized class or interface type might be an actual type or a constructed type
type TFoo1<T> = class(TBar) // Actual type end;
TFoo2<T> = class(TBar2<T>) // Open constructed type end;
TFoo3<T> = class(TBar3<Integer>) // Closed constructed type end;
->
// Actual type public class TFoo1<T> : TBar { public TFoo1() {} }; // Open constructed type public class TFoo2<T> : TBar2<T> { public TFoo2() {} }; // Closed constructed type public class TFoo3<T> : TBar2<int> { public TFoo3() {} };
Class, interface, record, and array types can be declared with type parameters.
type TRecord<T> = record FData: T; end;
type IAncestor<T> = interface function GetRecord: TRecord<T>; end;
IFoo<T> = interface(IAncestor<T>) procedure AMethod(Param: T); end;
type TFoo<T> = class(TObject, IFoo<T>) FField: TRecord<T>; procedure AMethod(Param: T); function GetRecord: TRecord<T>; end;
->
public struct TRecord<T> { public T FData; public static TRecord<T> CreateRecord(){return new TRecord<T>();} };
public interface IAncestor<T> : IInterface { TRecord<T> GetRecord(); };
public interface IFoo<T> : IAncestor<T> { void AMethod(T Param); };
public class TFoo<T> : TObject, IFoo<T> { public TRecord<T> FField = TRecord<T>.CreateRecord(); public void AMethod(T Param){...} public TRecord<T> GetRecord(){...}
public TFoo() {} };
|
This page belongs to the Delphi2C# Documentation |
Delphi2C# home Content |