collect.inc 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. {
  2. $Id$
  3. This file is part of the Free Component Library (FCL)
  4. Copyright (c) 1999-2000 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. FCollection:=Value;
  28. end;
  29. end;
  30. procedure TCollectionItem.Changed(AllItems: Boolean);
  31. begin
  32. If (FCollection<>Nil) then
  33. begin
  34. If AllItems then
  35. FCollection.Update(Nil)
  36. else
  37. FCollection.Update(Self);
  38. end;
  39. end;
  40. function TCollectionItem.GetNamePath: string;
  41. begin
  42. If FCollection<>Nil then
  43. Result:=FCollection.GetNamePath+'['+IntToStr(Index)+']'
  44. else
  45. Result:=ClassName;
  46. end;
  47. function TCollectionItem.GetOwner: TPersistent;
  48. begin
  49. Result:=FCollection;
  50. end;
  51. function TCollectionItem.GetDisplayName: string;
  52. begin
  53. Result:=ClassName;
  54. end;
  55. procedure TCollectionItem.SetIndex(Value: Integer);
  56. Var Temp : Longint;
  57. begin
  58. Temp:=GetIndex;
  59. If (Temp>-1) and (Temp<>Value) then
  60. begin
  61. FCollection.FItems.Move(Temp,Value);
  62. Changed(True);
  63. end;
  64. end;
  65. procedure TCollectionItem.SetDisplayName(const Value: string);
  66. begin
  67. Changed(False);
  68. end;
  69. constructor TCollectionItem.Create(ACollection: TCollection);
  70. begin
  71. Inherited Create;
  72. SetCollection(ACollection);
  73. end;
  74. destructor TCollectionItem.Destroy;
  75. begin
  76. SetCollection(Nil);
  77. Inherited Destroy;
  78. end;
  79. {****************************************************************************}
  80. {* TCollection *}
  81. {****************************************************************************}
  82. function TCollection.GetCount: Integer;
  83. begin
  84. If Assigned(FItems) Then
  85. Result:=FItems.Count
  86. else
  87. Result:=0;
  88. end;
  89. Procedure TCollection.SetPropName;
  90. begin
  91. //!! Should be replaced by the proper routines.
  92. FPropName:='';
  93. end;
  94. function TCollection.GetPropName: string;
  95. Var TheOWner : TPersistent;
  96. begin
  97. Result:=FPropNAme;
  98. TheOWner:=GetOwner;
  99. If (Result<>'') or (TheOwner=Nil) Or (TheOwner.Classinfo=Nil) then exit;
  100. SetPropName;
  101. Result:=FPropName;
  102. end;
  103. procedure TCollection.InsertItem(Item: TCollectionItem);
  104. begin
  105. If Not(Item Is FitemClass) then
  106. exit;
  107. FItems.add(Pointer(Item));
  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.FCollection:=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. Result:=TCollectionItem(FItems.Items[ItemIndex]).DisplayName;
  130. end;
  131. function TCollection.GetNamePath: string;
  132. Var OwnerName,ThePropName : String;
  133. begin
  134. Result:=ClassName;
  135. If GetOwner=Nil then Exit;
  136. OwnerName:=GetOwner.GetNamePath;
  137. If OwnerName='' then Exit;
  138. ThePropName:=PropName;
  139. if ThePropName='' then exit;
  140. Result:=OwnerName+'.'+PropName;
  141. end;
  142. procedure TCollection.Changed;
  143. begin
  144. Update(Nil);
  145. end;
  146. function TCollection.GetItem(Index: Integer): TCollectionItem;
  147. begin
  148. Result:=TCollectionItem(FItems.Items[Index]);
  149. end;
  150. procedure TCollection.SetItem(Index: Integer; Value: TCollectionItem);
  151. begin
  152. TCollectionItem(FItems.items[Index]).Assign(Value);
  153. end;
  154. procedure TCollection.SetItemName(Item: TCollectionItem);
  155. begin
  156. end;
  157. procedure TCollection.Update(Item: TCollectionItem);
  158. begin
  159. end;
  160. constructor TCollection.Create(AItemClass: TCollectionItemClass);
  161. begin
  162. inherited create;
  163. FItemClass:=AItemClass;
  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.items[I]);
  207. If Result.Id=Id then exit;
  208. end;
  209. end;
  210. {
  211. $Log$
  212. Revision 1.1 2003-10-06 20:33:58 peter
  213. * classes moved to rtl for 1.1
  214. * classes .inc and classes.pp files moved to fcl/classes for
  215. backwards 1.0.x compatiblity to have it in the fcl
  216. Revision 1.3 2002/09/07 15:15:24 peter
  217. * old logs removed and tabs fixed
  218. }