intf.inc 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. {%MainUnit classes.pp}
  2. {
  3. This file is part of the Free Component Library (FCL)
  4. Copyright (c) 2002 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. { TInerfaceListEnumerator }
  12. constructor TInterfaceListEnumerator.Create(AList: TInterfaceList);
  13. begin
  14. inherited create;
  15. FList:=AList;
  16. FPosition:=-1;
  17. end;
  18. function TInterfaceListEnumerator.GetCurrent: IUnknown;
  19. begin
  20. Result:=FList[FPosition];
  21. end;
  22. function TInterfaceListEnumerator.MoveNext: Boolean;
  23. begin
  24. Inc(FPosition);
  25. Result:=FPosition<FList.Count;
  26. end;
  27. { TInterfaceList }
  28. constructor TInterfaceList.Create;
  29. begin
  30. inherited create;
  31. FList:=TThreadList.Create;
  32. end;
  33. destructor TInterfaceList.Destroy;
  34. begin
  35. Clear;
  36. FList.Free;
  37. inherited Destroy;
  38. end;
  39. function TInterfaceList.Get(i : Integer) : IUnknown;
  40. begin
  41. FList.Locklist;
  42. try
  43. if (i<0) or (i>=FList.FList.Count) then
  44. FList.FList.Error(SListIndexError,i);
  45. result:=IUnknown(FList.FList.List^[i]);
  46. finally
  47. FList.UnlockList;
  48. end;
  49. end;
  50. function TInterfaceList.GetCapacity : Integer;
  51. begin
  52. FList.Locklist;
  53. try
  54. result:=FList.FList.Capacity;
  55. finally
  56. FList.UnlockList;
  57. end;
  58. end;
  59. function TInterfaceList.GetCount : Integer;
  60. begin
  61. FList.Locklist;
  62. try
  63. result:=FList.FList.Count;
  64. finally
  65. FList.UnlockList;
  66. end;
  67. end;
  68. procedure TInterfaceList.Put(i : Integer;item : IUnknown);
  69. begin
  70. FList.Locklist;
  71. try
  72. if (i<0) or (i>=FList.FList.Count) then
  73. FList.FList.Error(SListIndexError,i);
  74. IUnknown(FList.FList.List^[i]):=item;
  75. finally
  76. FList.UnlockList;
  77. end;
  78. end;
  79. procedure TInterfaceList.SetCapacity(NewCapacity : Integer);
  80. begin
  81. FList.Locklist;
  82. try
  83. FList.FList.Capacity:=NewCapacity;
  84. finally
  85. FList.UnlockList;
  86. end;
  87. end;
  88. procedure TInterfaceList.SetCount(NewCount : Integer);
  89. begin
  90. FList.Locklist;
  91. try
  92. FList.FList.Count:=NewCount;
  93. finally
  94. FList.UnlockList;
  95. end;
  96. end;
  97. procedure TInterfaceList.Clear;
  98. var
  99. i : SizeInt;
  100. begin
  101. FList.Locklist;
  102. try
  103. for i:=0 to FList.FList.Count-1 do
  104. IUnknown(FList.FList.List^[i]):=nil;
  105. FList.Clear;
  106. finally
  107. FList.UnlockList;
  108. end;
  109. end;
  110. procedure TInterfaceList.Delete(index : Integer);
  111. begin
  112. FList.Locklist;
  113. try
  114. if (index<0) or (index>=FList.FList.Count) then
  115. FList.FList.Error(SListIndexError,index);
  116. IUnknown(FList.FList.List^[index]):=nil;
  117. FList.FList.Delete(index);
  118. finally
  119. FList.UnlockList;
  120. end;
  121. end;
  122. procedure TInterfaceList.Exchange(index1,index2 : Integer);
  123. begin
  124. FList.Locklist;
  125. try
  126. FList.FList.Exchange(index1,index2);
  127. finally
  128. FList.UnlockList;
  129. end;
  130. end;
  131. function TInterfaceList.First : IUnknown;
  132. begin
  133. result:=Get(0);
  134. end;
  135. function TInterfaceList.GetEnumerator: TInterfaceListEnumerator;
  136. begin
  137. result:=TInterfaceListEnumerator.Create(Self)
  138. end;
  139. function TInterfaceList.IndexOf(const item : IUnknown) : Integer;
  140. begin
  141. FList.Locklist;
  142. try
  143. result:=FList.FList.IndexOf(Pointer(Item));
  144. finally
  145. FList.UnlockList;
  146. end;
  147. end;
  148. function TInterfaceList.Add(item : IUnknown) : Integer;
  149. begin
  150. FList.Locklist;
  151. try
  152. result:=FList.FList.Add(nil);
  153. IUnknown(FList.FList.List^[result]):=item;
  154. finally
  155. FList.UnlockList;
  156. end;
  157. end;
  158. procedure TInterfaceList.Insert(i : Integer;item : IUnknown);
  159. begin
  160. FList.Locklist;
  161. try
  162. FList.FList.Insert(i,nil);
  163. IUnknown(FList.FList.List^[i]):=item;
  164. finally
  165. FList.UnlockList;
  166. end;
  167. end;
  168. function TInterfaceList.Last : IUnknown;
  169. begin
  170. result:=Get(Count-1);
  171. end;
  172. function TInterfaceList.Remove(item : IUnknown): Integer;
  173. begin
  174. FList.Locklist;
  175. try
  176. result:=FList.FList.IndexOf(item);
  177. if result>=0 then
  178. begin
  179. IUnknown(FList.FList.List^[result]):=nil;
  180. FList.FList.Delete(result);
  181. end;
  182. finally
  183. FList.UnlockList;
  184. end;
  185. end;
  186. procedure TInterfaceList.Lock;
  187. begin
  188. FList.Locklist;
  189. end;
  190. procedure TInterfaceList.Unlock;
  191. begin
  192. FList.UnlockList;
  193. end;
  194. function TInterfaceList.Expand : TInterfaceList;
  195. begin
  196. FList.Locklist;
  197. try
  198. FList.FList.Expand;
  199. result:=self;
  200. finally
  201. FList.UnlockList;
  202. end;
  203. end;