collect.inc 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. {
  2. $Id$
  3. This file is part of the Free Component Library (FCL)
  4. Copyright (c) 1998 by the Free Pascal development team
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. {****************************************************************************}
  12. {* TCollectionItem *}
  13. {****************************************************************************}
  14. function TCollectionItem.GetIndex: Integer;
  15. begin
  16. if FCollection<>nil then
  17. Result:=FCollection.FItems.IndexOf(Pointer(Self))
  18. else
  19. Result:=-1;
  20. end;
  21. procedure TCollectionItem.SetCollection(Value: TCollection);
  22. begin
  23. IF Value<>FCollection then
  24. begin
  25. If FCollection<>Nil then FCollection.RemoveItem(Self);
  26. if Value<>Nil then Value.InsertItem(Self);
  27. end;
  28. end;
  29. procedure TCollectionItem.Changed(AllItems: Boolean);
  30. begin
  31. If (FCollection<>Nil) then
  32. begin
  33. If AllItems then
  34. FCollection.Update(Nil)
  35. else
  36. FCollection.Update(Self);
  37. end;
  38. end;
  39. function TCollectionItem.GetNamePath: string;
  40. begin
  41. If FCollection<>Nil then
  42. Result:=FCollection.GetNamePath+'['+IntToStr(Index)+']'
  43. else
  44. Result:=ClassName;
  45. end;
  46. function TCollectionItem.GetOwner: TPersistent;
  47. begin
  48. Result:=FCollection;
  49. end;
  50. function TCollectionItem.GetDisplayName: string;
  51. begin
  52. Result:=ClassName;
  53. end;
  54. procedure TCollectionItem.SetIndex(Value: Integer);
  55. Var Temp : Longint;
  56. begin
  57. Temp:=GetIndex;
  58. If (Temp>-1) and (Temp<>Value) then
  59. begin
  60. FCollection.FItems.Move(Temp,Value);
  61. Changed(True);
  62. end;
  63. end;
  64. procedure TCollectionItem.SetDisplayName(const Value: string);
  65. begin
  66. Changed(False);
  67. end;
  68. constructor TCollectionItem.Create(ACollection: TCollection);
  69. begin
  70. Inherited Create;
  71. SetCollection(ACollection);
  72. end;
  73. destructor TCollectionItem.Destroy;
  74. begin
  75. SetCollection(Nil);
  76. Inherited Destroy;
  77. end;
  78. {****************************************************************************}
  79. {* TCollection *}
  80. {****************************************************************************}
  81. function TCollection.GetCount: Integer;
  82. begin
  83. If Assigned(FItems) Then
  84. Result:=FItems.Count
  85. else
  86. Result:=0;
  87. end;
  88. Procedure TCollection.SetPropName;
  89. begin
  90. //!! Should be replaced by the proper routines.
  91. FPropName:='';
  92. end;
  93. function TCollection.GetPropName: string;
  94. Var TheOWner : TPersistent;
  95. begin
  96. Result:=FPropNAme;
  97. TheOWner:=GetOwner;
  98. If (Result<>'') or (TheOwner=Nil) Or (TheOwner.Classinfo=Nil) then exit;
  99. SetPropName;
  100. Result:=FPropName;
  101. end;
  102. procedure TCollection.InsertItem(Item: TCollectionItem);
  103. begin
  104. If Not(Item Is FitemClass) then
  105. exit;
  106. FItems.add(Pointer(Item));
  107. Item.Collection:=Self;
  108. Item.FID:=FNextID;
  109. inc(FNextID);
  110. SetItemName(Item);
  111. Changed;
  112. end;
  113. procedure TCollection.RemoveItem(Item: TCollectionItem);
  114. begin
  115. FItems.Remove(Pointer(Item));
  116. Item.Collection:=Nil;
  117. Changed;
  118. end;
  119. function TCollection.GetAttrCount: Integer;
  120. begin
  121. Result:=0;
  122. end;
  123. function TCollection.GetAttr(Index: Integer): string;
  124. begin
  125. Result:='';
  126. end;
  127. function TCollection.GetItemAttr(Index, ItemIndex: Integer): string;
  128. begin
  129. //!! Not Accepted !!
  130. //!! Result:=TCollectionItem(FItems[ItemIndex]).DisplayName;
  131. end;
  132. function TCollection.GetNamePath: string;
  133. Var OwnerName,ThePropName : String;
  134. begin
  135. Result:=ClassName;
  136. If GetOwner=Nil then Exit;
  137. OwnerName:=GetOwner.GetNamePath;
  138. If OwnerName='' then Exit;
  139. ThePropName:=PropName;
  140. if ThePropName='' then exit;
  141. Result:=OwnerName+'.'+PropName;
  142. end;
  143. procedure TCollection.Changed;
  144. begin
  145. Update(Nil);
  146. end;
  147. function TCollection.GetItem(Index: Integer): TCollectionItem;
  148. begin
  149. //!! Result:=FItems[Index];
  150. end;
  151. procedure TCollection.SetItem(Index: Integer; Value: TCollectionItem);
  152. begin
  153. //!! TCollectionItem(FItems[Index]).Assign(Value);
  154. end;
  155. procedure TCollection.SetItemName(Item: TCollectionItem);
  156. begin
  157. end;
  158. procedure TCollection.Update(Item: TCollectionItem);
  159. begin
  160. end;
  161. constructor TCollection.Create(AItemClass: TCollectionItemClass);
  162. begin
  163. FItemClass:=ItemClass;
  164. FItems:=TList.Create;
  165. end;
  166. destructor TCollection.Destroy;
  167. begin
  168. If Assigned(FItems) Then Clear;
  169. FItems.Free;
  170. Inherited Destroy;
  171. end;
  172. function TCollection.Add: TCollectionItem;
  173. begin
  174. Result:=FItemClass.Create(Self);
  175. end;
  176. procedure TCollection.Assign(Source: TPersistent);
  177. Var I : Longint;
  178. begin
  179. If Source is TCollection then
  180. begin
  181. Clear;
  182. For I:=0 To TCollection(Source).Count-1 do
  183. Add.Assign(TCollection(Source).Items[I]);
  184. exit;
  185. end
  186. else
  187. Inherited Assign(Source);
  188. end;
  189. procedure TCollection.BeginUpdate;
  190. begin
  191. end;
  192. procedure TCollection.Clear;
  193. begin
  194. //!! If Assigned(FItems) then
  195. //!! While FItems.Count>0 do TCollectionItem(FItems.Last).Free;
  196. end;
  197. procedure TCollection.EndUpdate;
  198. begin
  199. end;
  200. function TCollection.FindItemID(ID: Integer): TCollectionItem;
  201. Var I : Longint;
  202. begin
  203. Result:=Nil;
  204. For I:=0 to Fitems.Count-1 do
  205. begin
  206. //!! Result:=TCollectionItem(FItems[I]);
  207. If Result.Id=Id then exit;
  208. end;
  209. end;
  210. {
  211. $Log$
  212. Revision 1.2 1998-05-27 11:41:41 michael
  213. Implemented TCollection and TCollectionItem
  214. Revision 1.1 1998/05/04 14:30:11 michael
  215. * Split file according to Class; implemented dummys for all methods, so unit compiles.
  216. }