intf.inc 5.4 KB

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