dmitrybv 3 Posted December 6 Good day. How does the IDesigner.CreateComponent method work? function CreateComponent(ComponentClass: TComponentClass; Parent: TComponent; Left, Top, Width, Height: Integer): TComponent; How does CreateComponent call the correct method on the created component to pass the Parent parameter to it? If I created my component by inheriting TComponent and my component has a method procedure TMyComponent.SetParent(AParent: TMyParentComponent); then how can I pass to the IDesigner.CreateComponent function an indication that after creating my component it should call MyComponent.SetParent(Parent)? Share this post Link to post
Remy Lebeau 1429 Posted December 6 (edited) Arbitrary components don't have a Parent. TComponent does not have a SetParent() method. So, unless CreateComponent() is using RTTI, it won't have any knowledge of your custom SetParent() method. And it certainly won't be able to call it since it won't have access to TMyParentComponent. Only TControl-derived components have a Parent. I expect CreateComponent() to check if the specified class type is a TControl descendant, and if so then cast the created object to TControl in order to set its TControl.Parent property, as well as its TControl.Left/Top/Width/Height properties (probably by calling TControl.SetBounds()). Edited December 6 by Remy Lebeau Share this post Link to post
dmitrybv 3 Posted December 6 TComponent has a method: procedure SetParentComponent(Value: TComponent); dynamic; It is used when loading components from a stream. IDesigner.CreateComponent does not call this method, although it could. Share this post Link to post