compon.inc 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502
  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. {****************************************************************************}
  12. {* TComponent *}
  13. {****************************************************************************}
  14. Type
  15. Longrec = Record
  16. Hi,lo : word;
  17. end;
  18. Function TComponent.GetComponent(AIndex: Integer): TComponent;
  19. begin
  20. If not assigned(FComponents) then
  21. Result:=Nil
  22. else
  23. Result:=TComponent(FComponents.Items[Aindex]);
  24. end;
  25. Function TComponent.GetComponentCount: Integer;
  26. begin
  27. If not assigned(FComponents) then
  28. result:=0
  29. else
  30. Result:=FComponents.Count;
  31. end;
  32. Function TComponent.GetComponentIndex: Integer;
  33. begin
  34. If Assigned(FOwner) and Assigned(FOwner.FComponents) then
  35. Result:=FOWner.FComponents.IndexOf(Self)
  36. else
  37. Result:=-1;
  38. end;
  39. Procedure TComponent.Insert(AComponent: TComponent);
  40. begin
  41. If not assigned(FComponents) then
  42. FComponents:=TList.Create;
  43. FComponents.Add(AComponent);
  44. AComponent.FOwner:=Self;
  45. end;
  46. Procedure TComponent.ReadLeft(Reader: TReader);
  47. begin
  48. // LongRec(FDesignInfo).Lo:=Reader.ReadInteger;
  49. end;
  50. Procedure TComponent.ReadTop(Reader: TReader);
  51. begin
  52. // LongRec(FDesignInfo).Hi:=Reader.ReadInteger;
  53. end;
  54. Procedure TComponent.Remove(AComponent: TComponent);
  55. begin
  56. AComponent.FOwner:=Nil;
  57. If assigned(FCOmponents) then
  58. begin
  59. FComponents.Remove(AComponent);
  60. IF FComponents.Count=0 then
  61. begin
  62. FComponents.Free;
  63. FComponents:=Nil;
  64. end;
  65. end;
  66. end;
  67. Procedure TComponent.SetComponentIndex(Value: Integer);
  68. Var Temp,Count : longint;
  69. begin
  70. If Not assigned(Fowner) then exit;
  71. Temp:=getcomponentindex;
  72. If temp<0 then exit;
  73. If value<0 then value:=0;
  74. Count:=Fowner.FComponents.Count;
  75. If Value>=Count then value:=count-1;
  76. If Value<>Temp then
  77. begin
  78. FOWner.FComponents.Delete(Temp);
  79. FOwner.FComponents.Insert(Value,Self);
  80. end;
  81. end;
  82. Procedure TComponent.SetReference(Enable: Boolean);
  83. begin
  84. // For delphi compatibility only.
  85. end;
  86. Procedure TComponent.WriteLeft(Writer: TWriter);
  87. begin
  88. Writer.WriteInteger(LongRec(FDesignInfo).Lo);
  89. end;
  90. Procedure TComponent.WriteTop(Writer: TWriter);
  91. begin
  92. Writer.WriteInteger(LongRec(FDesignInfo).Hi);
  93. end;
  94. Procedure TComponent.ChangeName(const NewName: TComponentName);
  95. begin
  96. FName:=NewName;
  97. end;
  98. Procedure TComponent.DefineProperties(Filer: TFiler);
  99. Var Ancestor : TComponent;
  100. Temp : longint;
  101. begin
  102. Temp:=0;
  103. Ancestor:=TComponent(Filer.Ancestor);
  104. If Assigned(Ancestor) then Temp:=Ancestor.FDesignInfo;
  105. {
  106. Filer.Defineproperty('left',readleft,writeleft,
  107. (longrec(FDesignInfo).Lo<>Longrec(temp).Lo));
  108. Filer.Defineproperty('top',readtop,writetop,
  109. (longrec(FDesignInfo).Hi<>Longrec(temp).Hi));
  110. }
  111. end;
  112. Procedure TComponent.GetChildren(Proc: TGetChildProc; Root: TComponent);
  113. begin
  114. // Does nothing.
  115. end;
  116. Function TComponent.GetChildOwner: TComponent;
  117. begin
  118. Result:=Nil;
  119. end;
  120. Function TComponent.GetChildParent: TComponent;
  121. begin
  122. Result:=Self;
  123. end;
  124. Function TComponent.GetNamePath: string;
  125. begin
  126. Result:=FName;
  127. end;
  128. Function TComponent.GetOwner: TPersistent;
  129. begin
  130. Result:=FOwner;
  131. end;
  132. Procedure TComponent.Loaded;
  133. begin
  134. Exclude(FComponentState,csLoading);
  135. end;
  136. Procedure TComponent.Notification(AComponent: TComponent;
  137. Operation: TOperation);
  138. Var Runner : Longint;
  139. begin
  140. If (Operation=opRemove) and Assigned(FFreeNotifies) then
  141. begin
  142. FFreeNotifies.Remove(AComponent);
  143. If FFreeNotifies.Count=0 then
  144. begin
  145. FFreeNotifies.Free;
  146. FFreenotifies:=Nil;
  147. end;
  148. end;
  149. If assigned(FComponents) then
  150. For Runner:=0 To FComponents.Count-1 do
  151. TComponent(FComponents.Items[Runner]).Notification(AComponent,Operation);
  152. end;
  153. Procedure TComponent.ReadState(Reader: TAbstractReader);
  154. begin
  155. //!! Reader.ReadData(Self);
  156. end;
  157. Procedure TComponent.SetAncestor(Value: Boolean);
  158. Var Runner : Longint;
  159. begin
  160. If Value then
  161. Include(FComponentState,csAncestor)
  162. else
  163. Include(FCOmponentState,csAncestor);
  164. if Assigned(FComponents) then
  165. For Runner:=0 To FComponents.Count do
  166. TComponent(FComponents.Items[Runner]).SetAncestor(Value);
  167. end;
  168. Procedure TComponent.SetDesigning(Value: Boolean);
  169. Var Runner : Longint;
  170. begin
  171. If Value then
  172. Include(FComponentSTate,csDesigning)
  173. else
  174. Exclude(FComponentSTate,csDesigning);
  175. if Assigned(FComponents) then
  176. For Runner:=0 To FComponents.Count do
  177. TComponent(FComponents.items[Runner]).SetDesigning(Value);
  178. end;
  179. Procedure TComponent.SetName(const NewName: TComponentName);
  180. begin
  181. If FName=NewName then exit;
  182. If not IsValidIdent(NewName) then
  183. Raise EComponentError.CreateFmt(SInvalidName,[NewName]);
  184. If Assigned(FOwner) Then
  185. FOwner.ValidateRename(Self,FName,NewName)
  186. else
  187. ValidateRename(Nil,FName,NewName);
  188. SetReference(False);
  189. ChangeName(NewName);
  190. Setreference(True);
  191. end;
  192. Procedure TComponent.SetChildOrder(Child: TComponent; Order: Integer);
  193. begin
  194. // does nothing
  195. end;
  196. Procedure TComponent.SetParentComponent(Value: TComponent);
  197. begin
  198. // Does nothing
  199. end;
  200. Procedure TComponent.Updating;
  201. begin
  202. Include (FComponentState,csUpdating);
  203. end;
  204. Procedure TComponent.Updated;
  205. begin
  206. Exclude(FComponentState,csUpdating);
  207. end;
  208. class Procedure TComponent.UpdateRegistry(Register: Boolean; const ClassID, ProgID: string);
  209. begin
  210. // For compatibility only.
  211. end;
  212. Procedure TComponent.ValidateRename(AComponent: TComponent;
  213. const CurName, NewName: string);
  214. begin
  215. //!! This contradicts the Delphi manual.
  216. If (AComponent<>Nil) and (CurName<>NewName) and
  217. (FindComponent(NewName)<>Nil) then
  218. raise EComponentError.Createfmt(SDuplicateName,[newname]);
  219. If (csDesigning in FComponentState) and (FOwner<>Nil) then
  220. FOwner.ValidateRename(AComponent,Curname,Newname);
  221. end;
  222. Procedure TComponent.ValidateContainer(AComponent: TComponent);
  223. begin
  224. end;
  225. Procedure TComponent.ValidateInsert(AComponent: TComponent);
  226. begin
  227. // Does nothing.
  228. end;
  229. Procedure TComponent.WriteState(Writer: TAbstractWriter);
  230. begin
  231. Writer.WriteData(self);
  232. end;
  233. Constructor TComponent.Create(AOwner: TComponent);
  234. begin
  235. FComponentStyle:=[csInheritable];
  236. If Assigned(AOwner) then AOwner.InsertComponent(Self);
  237. end;
  238. Destructor TComponent.Destroy;
  239. Var Runner : Longint;
  240. begin
  241. If Assigned(FFreeNotifies) then
  242. begin
  243. For Runner:=0 To FFreeNotifies.Count-1 do
  244. TComponent(FFreeNotifies.Items[Runner]).Notification (self,opRemove);
  245. FFreeNotifies.Free;
  246. FFreeNotifies:=Nil;
  247. end;
  248. Destroying;
  249. DestroyComponents;
  250. If FOwner<>Nil Then FOwner.RemoveComponent(Self);
  251. inherited destroy;
  252. end;
  253. Procedure TComponent.DestroyComponents;
  254. Var acomponent: TComponent;
  255. begin
  256. While assigned(FComponents) do
  257. begin
  258. aComponent:=TComponent(FComponents.Last);
  259. Remove(aComponent);
  260. Acomponent.Destroy;
  261. end;
  262. end;
  263. Procedure TComponent.Destroying;
  264. Var Runner : longint;
  265. begin
  266. If csDestroying in FComponentstate Then Exit;
  267. include (FComponentState,csDestroying);
  268. If Assigned(FComponents) then
  269. for Runner:=0 to FComponents.Count-1 do
  270. TComponent(FComponents.Items[Runner]).Destroying;
  271. end;
  272. Function TComponent.FindComponent(const AName: string): TComponent;
  273. Var I : longint;
  274. begin
  275. Result:=Nil;
  276. If (AName='') or Not assigned(FComponents) then exit;
  277. For i:=0 to FComponents.Count-1 do
  278. if TComponent(FComponents[I]).Name=AName then
  279. begin
  280. Result:=TComponent(FComponents.Items[I]);
  281. exit;
  282. end;
  283. end;
  284. Procedure TComponent.FreeNotification(AComponent: TComponent);
  285. begin
  286. If (Owner<>Nil) and (AComponent=Owner) then exit;
  287. If not (Assigned(FFreeNotifies)) then
  288. FFreeNotifies:=TList.Create;
  289. If FFreeNotifies.IndexOf(AComponent)=-1 then
  290. begin
  291. FFreeNotifies.Add(AComponent);
  292. AComponent.FreeNotification (self);
  293. end;
  294. end;
  295. Procedure TComponent.FreeOnRelease;
  296. begin
  297. // Delphi compatibility only at the moment.
  298. end;
  299. Function TComponent.GetParentComponent: TComponent;
  300. begin
  301. Result:=Nil;
  302. end;
  303. Function TComponent.HasParent: Boolean;
  304. begin
  305. Result:=False;
  306. end;
  307. Procedure TComponent.InsertComponent(AComponent: TComponent);
  308. begin
  309. AComponent.ValidateContainer(Self);
  310. ValidateRename(AComponent,'',AComponent.FName);
  311. Insert(AComponent);
  312. AComponent.SetReference(True);
  313. If csDesigning in FComponentState then
  314. AComponent.SetDesigning(true);
  315. Notification(AComponent,opInsert);
  316. end;
  317. Procedure TComponent.RemoveComponent(AComponent: TComponent);
  318. begin
  319. Notification(AComponent,opRemove);
  320. AComponent.SetReference(False);
  321. Remove(AComponent);
  322. Acomponent.Setdesigning(False);
  323. ValidateRename(AComponent,AComponent.FName,'');
  324. end;
  325. Function TComponent.SafeCallException(ExceptObject: TObject;
  326. ExceptAddr: Pointer): Integer;
  327. begin
  328. SafeCallException:=0;
  329. end;
  330. {
  331. $Log$
  332. Revision 1.11 2000-01-07 01:24:33 peter
  333. * updated copyright to 2000
  334. Revision 1.10 2000/01/06 01:20:32 peter
  335. * moved out of packages/ back to topdir
  336. Revision 1.2 2000/01/04 18:07:16 michael
  337. + Streaming implemented
  338. Revision 1.1 2000/01/03 19:33:07 peter
  339. * moved to packages dir
  340. Revision 1.8 1999/04/12 14:41:00 michael
  341. + Fixed TComponent methods where defaults are used
  342. Revision 1.7 1999/04/12 08:02:48 michael
  343. + Fixed bug in ValidateRename
  344. Revision 1.6 1999/04/08 10:18:51 peter
  345. * makefile updates
  346. }