cregist.inc 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. {%MainUnit classes.pp}
  2. {
  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. { Class registration routines }
  12. procedure RegisterClass(AClass: TPersistentClass);
  13. begin
  14. //Classlist is created during initialization.
  15. with Classlist.Locklist do
  16. try
  17. while Indexof(AClass) = -1 do
  18. begin
  19. if GetClass(AClass.Unitname,AClass.ClassName) <> nil then //class alread registered!
  20. Begin
  21. //raise an error
  22. exit;
  23. end;
  24. Add(AClass);
  25. if AClass = TPersistent then break;
  26. AClass := TPersistentClass(AClass.ClassParent);
  27. end;
  28. finally
  29. ClassList.UnlockList;
  30. end;
  31. end;
  32. procedure RegisterClassAlias(AClass: TPersistentClass; const Alias: string);
  33. var
  34. I : integer;
  35. begin
  36. I:=-1;
  37. ClassList.LockList;
  38. try
  39. if ClassAliasList=nil then
  40. ClassAliasList := TStringList.Create
  41. else
  42. i := ClassAliasList.IndexOf(Alias);
  43. if I = -1 then
  44. ClassAliasList.AddObject( Alias, TObject(AClass) );
  45. finally
  46. ClassList.UnlockList;
  47. end;
  48. end;
  49. procedure RegisterClasses(AClasses: array of TPersistentClass);
  50. var
  51. I : Integer;
  52. begin
  53. for I := low(aClasses) to high(aClasses) do
  54. RegisterClass(aClasses[I]);
  55. end;
  56. procedure UnRegisterClass(AClass: TPersistentClass);
  57. var
  58. i: Integer;
  59. begin
  60. with ClassList.LockList do
  61. try
  62. Remove(AClass);
  63. if Assigned(ClassAliasList) then
  64. for i:=ClassAliasList.Count-1 downto 0 do
  65. if TPersistentClass(ClassAliasList.Objects[i])=AClass then
  66. ClassAliasList.Delete(i);
  67. finally
  68. ClassList.UnlockList;
  69. end;
  70. end;
  71. procedure UnRegisterClasses(const AClasses: array of TPersistentClass);
  72. var
  73. i: Integer;
  74. begin
  75. for i:=Low(AClasses) to high(AClasses) do
  76. UnRegisterClass(AClasses[i]);
  77. end;
  78. procedure UnRegisterModuleClasses(Module: HMODULE);
  79. begin
  80. end;
  81. function FindClass(const AClassName: string): TPersistentClass;
  82. begin
  83. Result := FindClass('',AClassName);
  84. end;
  85. function FindClass(const anUnitname, aClassName: string): TPersistentClass;
  86. begin
  87. Result := GetClass(anUnitname,aClassName);
  88. if not Assigned(Result) then
  89. if anUnitname<>'' then
  90. raise EClassNotFound.CreateFmt(SClassNotFound, [anUnitname+'/'+AClassName])
  91. else
  92. raise EClassNotFound.CreateFmt(SClassNotFound, [AClassName]);
  93. end;
  94. function GetClass(const AClassName: string): TPersistentClass;
  95. begin
  96. Result:=GetClass('',AClassName);
  97. end;
  98. function GetClass(const anUnitname, aClassName: string): TPersistentClass;
  99. var
  100. I : Integer;
  101. begin
  102. with ClassList.LockList do
  103. try
  104. for I := 0 to Count-1 do
  105. begin
  106. Result := TPersistentClass(Items[I]);
  107. if not Result.ClassNameIs(AClassName) then
  108. continue;
  109. if (anUnitname='') or SameText(anUnitname,Result.UnitName) then
  110. exit;
  111. end;
  112. if Assigned(ClassAliasList) then
  113. begin
  114. I:=-1;
  115. if anUnitname<>'' then
  116. I := ClassAliasList.Indexof(anUnitname+'/'+AClassName);
  117. if I<0 then
  118. I := ClassAliasList.Indexof(AClassName);
  119. if I >= 0 then //found
  120. Begin
  121. Result := TPersistentClass(ClassAliasList.Objects[i]);
  122. exit;
  123. end;
  124. end;
  125. Result := nil;
  126. finally
  127. ClassList.Unlocklist;
  128. end;
  129. end;
  130. procedure StartClassGroup(AClass: TPersistentClass);
  131. begin
  132. end;
  133. procedure GroupDescendentsWith(AClass, AClassGroup: TPersistentClass);
  134. begin
  135. end;
  136. function ActivateClassGroup(AClass: TPersistentClass): TPersistentClass;
  137. begin
  138. Result:=nil;
  139. end;
  140. function ClassGroupOf(AClass: TPersistentClass): TPersistentClass;
  141. begin
  142. Result:=nil;
  143. end;
  144. function ClassGroupOf(Instance: TPersistent): TPersistentClass;
  145. begin
  146. Result:=nil;
  147. end;
  148. { Component registration routines }
  149. type
  150. TComponentPage = class(TCollectionItem)
  151. public
  152. Name: String;
  153. Classes: TList;
  154. destructor Destroy; override;
  155. end;
  156. { TComponentPage }
  157. destructor TComponentPage.Destroy;
  158. begin
  159. Classes.Free;
  160. inherited Destroy;
  161. end;
  162. var
  163. ComponentPages: TCollection;
  164. procedure InitComponentPages;
  165. begin
  166. ComponentPages := TCollection.Create(TComponentPage);
  167. { Add a empty page which will be used for storing the NoIcon components }
  168. ComponentPages.Add;
  169. end;
  170. procedure RegisterComponents(const Page: string;
  171. ComponentClasses: array of TComponentClass);
  172. var
  173. i: Integer;
  174. pg: TComponentPage;
  175. begin
  176. if Page = '' then exit; { prevent caller from doing nonsense }
  177. pg := nil;
  178. if not Assigned(ComponentPages) then
  179. InitComponentPages
  180. else
  181. for i := 0 to ComponentPages.Count - 1 do
  182. if TComponentPage(ComponentPages.Items[i]).Name = Page then begin
  183. pg := TComponentPage(ComponentPages.Items[i]);
  184. break;
  185. end;
  186. if pg = nil then begin
  187. pg := TComponentPage(ComponentPages.Add);
  188. pg.Name := Page;
  189. end;
  190. if pg.Classes = nil then
  191. pg.Classes := TList.Create;
  192. for i := Low(ComponentClasses) to High(ComponentClasses) do
  193. pg.Classes.Add(ComponentClasses[i]);
  194. if Assigned(RegisterComponentsProc) then
  195. RegisterComponentsProc(Page, ComponentClasses);
  196. end;
  197. procedure RegisterNoIcon(ComponentClasses: array of TComponentClass);
  198. var
  199. pg: TComponentPage;
  200. i: Integer;
  201. begin
  202. if not Assigned(ComponentPages) then
  203. InitComponentPages;
  204. pg := TComponentPage(ComponentPages.Items[0]);
  205. if pg.Classes = nil then
  206. pg.Classes := TList.Create;
  207. for i := Low(ComponentClasses) to High(ComponentClasses) do
  208. pg.Classes.Add(ComponentClasses[i]);
  209. if Assigned(RegisterNoIconProc) then
  210. RegisterNoIconProc(ComponentClasses);
  211. end;
  212. procedure RegisterNonActiveX(ComponentClasses: array of TComponentClass;
  213. AxRegType: TActiveXRegType);
  214. begin
  215. end;