Delphi 泛型详解

 {
   很早就写了. 只针对delphixe 以上的版本可用.
  希望不是自己在造轮子. 
 }
 1 unit U_ClassUtility; 2  3 interface 4   uses generics.defaults,DateUtils,Classes,SysUtils,Windows, generics.collections; 5  6 type 7    TGenericList<T> = class 8    private 9       fList : Tlist<T>;10       procedure SetList(const Value: TList<T>);11    public12       procedure clear;13       procedure Add;14 15       constructor Create;16       destructor Destroy; override;17       property List : TList<T> read FList write SetList;18    end;19 20 implementation21 { TGenericList<T> }22 23 procedure TGenericList<T>.Add;24 begin25   fList.Add;26 end;27 28 procedure TGenericList<T>.clear;29 var30   i : Integer;31 begin32   for I := 0 to fList.Count -1 do33    TObject(fList.Items[i]).Free;34 35   fList.Clear;36 end;37 38 constructor TGenericList<T>.Create;39 begin40   fList :=  TList<T>.Create;41 end;42 43 destructor TGenericList<T>.Destroy;44 begin45   clear;46   fList.Free;47   inherited;48 end;49 50 procedure TGenericList<T>.SetList(const Value: TList<T>);51 begin52   FList := Value;53 end;54 55 end.

http://www.cnblogs.com/jxgxy/category/216671.html

发表评论

电子邮件地址不会被公开。 必填项已用*标注

网站地图xml地图