{
很早就写了. 只针对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 public
12 procedure clear;
13 procedure Add(Aobj : T);
14
15 constructor Create;
16 destructor Destroy; override;
17 property List : TList<T> read FList write SetList;
18 end;
19
20 implementation
21 { TGenericList<T> }
22
23 procedure TGenericList<T>.Add(Aobj: T);
24 begin
25 fList.Add(Aobj);
26 end;
27
28 procedure TGenericList<T>.clear;
29 var
30 i : Integer;
31 begin
32 for I := 0 to fList.Count -1 do
33 TObject(fList.Items[i]).Free;
34
35 fList.Clear;
36 end;
37
38 constructor TGenericList<T>.Create;
39 begin
40 fList := TList<T>.Create;
41 end;
42
43 destructor TGenericList<T>.Destroy;
44 begin
45 clear;
46 fList.Free;
47 inherited;
48 end;
49
50 procedure TGenericList<T>.SetList(const Value: TList<T>);
51 begin
52 FList := Value;
53 end;
54
55 end.