Changeset 326 for Generics/NativeGenerics/Units/GenericTree.pas
- Timestamp:
- Feb 8, 2012, 2:13:08 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Generics/NativeGenerics/Units/GenericTree.pas
r132 r326 9 9 10 10 type 11 // TGTreeNode<TItem> = class;12 11 13 // TGTreeNodeList = TGList<TGTreeNode>; 12 { TGAbstractTreeNode } 14 13 15 TGTreeNode<TItem> = class 16 // Childs: ; 17 Value: TItem; 18 procedure Clear; 14 TGAbstractTreeNode<TItem> = class 15 private 16 function GetValue: TItem; virtual; abstract; 17 procedure SetValue(AValue: TItem); virtual; abstract; 18 public 19 type 20 TNode = TGAbstractTreeNode<TItem>; 21 var 22 Childs: TGAbstractList<TNode>; 23 procedure Clear; virtual; abstract; 24 constructor Create; virtual; 25 destructor Destroy; override; 26 property Value: TItem read GetValue write SetValue; 27 end; 28 29 { TGAbstractTree } 30 31 TGAbstractTree<TItem> = class 32 public 33 type 34 TNode = TGAbstractTreeNode<TItem>; 35 TIndex = NativeInt; 36 private 37 function GetItem(Index: TIndex): TItem; 38 procedure SetItem(Index: TIndex; AValue: TItem); 39 var 40 TopItem: TGAbstractTreeNode<TItem>; 41 procedure Clear; virtual; abstract; 42 constructor Create; virtual; 43 property Items[Index: TIndex]: TItem read GetItem write SetItem; 44 end; 45 46 47 TGTreeNode<TItem> = class(TGAbstractTreeNode<TItem>) 48 public 49 type 50 TNode = TGTreeNode<TItem>; 51 private 52 FValue: TItem; 53 function GetValue: TItem; override; 54 procedure SetValue(AValue: TItem); override; 55 public 56 procedure Clear; override; 57 constructor Create; override; 58 destructor Destroy; override; 19 59 end; 20 60 21 61 TGTree<TItem> = class 22 // TopItem: TGTreeNode; 23 procedure Clear; 62 public 63 type 64 TNode = TGTreeNode<TItem>; 65 private 66 FItems: TGList<TNode>; 67 public 68 procedure Clear; override; 69 constructor Create; override; 70 destructor Destroy; override; 24 71 end; 72 25 73 26 74 implementation 27 75 28 76 { TGTreeNode } 77 78 function TGTreeNode<TItem>.GetValue: TItem; 79 begin 80 Result := FValue; 81 end; 82 83 procedure TGTreeNode<TItem>.SetValue(AValue: TItem); 84 begin 85 FValue := AValue; 86 end; 29 87 30 88 procedure TGTreeNode<TItem>.Clear; … … 40 98 end; 41 99 100 constructor TGTree<TItem>.Create; 101 begin 102 inherited; 103 FItems := TGList<TNode>.Create; 104 end; 105 106 destructor TGTree<TItem>.Destroy; 107 begin 108 inherited Destroy; 109 FItems.Free; 110 end; 111 112 { TGAbstractTree<TItem> } 113 114 function TGAbstractTree<TItem>.GetItem(Index: TIndex): TItem; 115 begin 116 117 end; 118 119 procedure TGAbstractTree<TItem>.SetItem(Index: TIndex; AValue: TItem); 120 begin 121 122 end; 123 124 constructor TGAbstractTree<TItem>.Create; 125 begin 126 end; 127 128 constructor TGTreeNode<TItem>.Create; 129 begin 130 inherited; 131 Childs := TGList<TNode>.Create; 132 end; 133 134 destructor TGTreeNode<TItem>.Destroy; 135 begin 136 Childs.Free; 137 inherited; 138 end; 139 140 { TGAbstractTreeNode<TItem> } 141 142 constructor TGAbstractTreeNode<TItem>.Create; 143 begin 144 end; 145 146 destructor TGAbstractTreeNode<TItem>.Destroy; 147 begin 148 inherited Destroy; 149 end; 150 151 42 152 end.
Note:
See TracChangeset
for help on using the changeset viewer.