cregist.inc 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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. { Class registration routines }
  12. procedure RegisterClass(AClass: TPersistentClass);
  13. var
  14. aClassname : String;
  15. begin
  16. //Classlist is created during initialization.
  17. with Classlist.Locklist do
  18. try
  19. while Indexof(AClass) = -1 do
  20. begin
  21. aClassname := AClass.ClassName;
  22. if GetClass(aClassName) <> nil then //class alread registered!
  23. Begin
  24. //raise an error
  25. exit;
  26. end;
  27. Add(AClass);
  28. if AClass = TPersistent then break;
  29. AClass := TPersistentClass(AClass.ClassParent);
  30. end;
  31. finally
  32. ClassList.UnlockList;
  33. end;
  34. end;
  35. procedure RegisterClasses(AClasses: array of TPersistentClass);
  36. var
  37. I : Integer;
  38. begin
  39. for I := low(aClasses) to high(aClasses) do
  40. RegisterClass(aClasses[I]);
  41. end;
  42. procedure RegisterClassAlias(AClass: TPersistentClass; const Alias: string);
  43. begin
  44. end;
  45. procedure UnRegisterClass(AClass: TPersistentClass);
  46. begin
  47. end;
  48. procedure UnRegisterClasses(AClasses: array of TPersistentClass);
  49. begin
  50. end;
  51. procedure UnRegisterModuleClasses(Module: HMODULE);
  52. begin
  53. end;
  54. function FindClass(const AClassName: string): TPersistentClass;
  55. begin
  56. Result := GetClass(AClassName);
  57. if not Assigned(Result) then
  58. raise EClassNotFound.CreateFmt(SClassNotFound, [AClassName]);
  59. end;
  60. function GetClass(const AClassName: string): TPersistentClass;
  61. var
  62. I : Integer;
  63. begin
  64. with ClassList.LockList do
  65. try
  66. for I := 0 to Count-1 do
  67. begin
  68. Result := TPersistentClass(Items[I]);
  69. if Result.ClassNameIs(AClassName) then Exit;
  70. end;
  71. I := ClassAliasList.Indexof(AClassName);
  72. if I >= 0 then //found
  73. Begin
  74. Result := TPersistentClass(ClassAliasList.Objects[i]);
  75. exit;
  76. end;
  77. Result := nil;
  78. finally
  79. ClassList.Unlocklist;
  80. end;
  81. end;
  82. { Component registration routines }
  83. type
  84. TComponentPage = class(TCollectionItem)
  85. public
  86. Name: String;
  87. Classes: TList;
  88. end;
  89. var
  90. ComponentPages: TCollection;
  91. procedure InitComponentPages;
  92. begin
  93. ComponentPages := TCollection.Create(TComponentPage);
  94. { Add a empty page which will be used for storing the NoIcon components }
  95. ComponentPages.Add;
  96. end;
  97. procedure RegisterComponents(const Page: string;
  98. ComponentClasses: array of TComponentClass);
  99. var
  100. i: Integer;
  101. pg: TComponentPage;
  102. begin
  103. if Page = '' then exit; { prevent caller from doing nonsense }
  104. pg := nil;
  105. if not Assigned(ComponentPages) then
  106. InitComponentPages
  107. else
  108. for i := 0 to ComponentPages.Count - 1 do
  109. if TComponentPage(ComponentPages.Items[i]).Name = Page then begin
  110. pg := TComponentPage(ComponentPages.Items[i]);
  111. break;
  112. end;
  113. if pg = nil then begin
  114. pg := TComponentPage(ComponentPages.Add);
  115. pg.Name := Page;
  116. end;
  117. if pg.Classes = nil then
  118. pg.Classes := TList.Create;
  119. for i := Low(ComponentClasses) to High(ComponentClasses) do
  120. pg.Classes.Add(ComponentClasses[i]);
  121. if Assigned(RegisterComponentsProc) then
  122. RegisterComponentsProc(Page, ComponentClasses);
  123. end;
  124. procedure RegisterNoIcon(ComponentClasses: array of TComponentClass);
  125. var
  126. pg: TComponentPage;
  127. i: Integer;
  128. begin
  129. if not Assigned(ComponentPages) then
  130. InitComponentPages;
  131. pg := TComponentPage(ComponentPages.Items[0]);
  132. if pg.Classes = nil then
  133. pg.Classes := TList.Create;
  134. for i := Low(ComponentClasses) to High(ComponentClasses) do
  135. pg.Classes.Add(ComponentClasses[i]);
  136. if Assigned(RegisterNoIconProc) then
  137. RegisterNoIconProc(ComponentClasses);
  138. end;
  139. procedure RegisterNonActiveX(ComponentClasses: array of TComponentClass;
  140. AxRegType: TActiveXRegType);
  141. begin
  142. end;
  143. {
  144. $Log$
  145. Revision 1.3 2001-02-09 20:40:12 sg
  146. * Fixed GetClass function (merged from Fixbranch)
  147. Revision 1.2 2000/07/13 11:32:59 michael
  148. + removed logs
  149. }