We have some legacy delphi custom components that override createwnd. These components sit on a panel within a form.
When the form and panel get instantiated, so do the components, and createwnd is called once. This makes sense.
I was surprised to discover that createwnd will gets called again however, if I switch the parent of the panel during runtime.
Eg, under certain circumstances I might change the parent container of Panel1 to be Form2.panel2. Basically drawing Panel1 inside Form2's panel at runtime.
TForm1.buttonclick(..)
begin
..
Panel1.parent := Form2.panel2;
..
end;
Why are the custom components in Panel1 being recreated, when the parent changes?
And is the behavior the same for all components in Panel1, even ones that are not custom, for example if I also had a TButton on Panel1, would that also get recreated when parents are switched? I don't think it does, which is why I was so surprised.
Finally, if this behavior is incorrect, how do I make it so createwnd doesn't get called when parent containers change.
Thank you!