intf.inc 4.8 KB

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