Jump to content
dmitrybv

How does the IDesigner.CreateComponent method work?

Recommended Posts

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

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 by Remy Lebeau

Share this post


Link to post

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×