Being on Manjaro Linux / qt6 I can confirm the issue after pasting your code into a separate unit and installing it via an own package. I cannot confirm when the component is created at runtime where there is only a single button.
I think (not 100% sure, though) the issue is in your intention to have the button in the object tree of the object inspector. For this purpose you override the method GetChildren. When I comment this method out and rebuild the IDE, the button appears only once - but now there is no "MyButton" subnode in the object tree underneath "CustomPanelWithButton", and you don't have access to the button any more.
Another way to stream the button properties would be to move its declaration from the public to the published section of the class. Now - after rebuilding the IDE again - the button can be found as a regular property of the control, and you can control its properties.
But do you really want this? Your code centers the button inside the panel. But when the user has access to the button properties it can overwrite the Left and Top properties and move it somewhere else at designtime - but at runtime it will be in the center again due to "SetButtonPosition" in "CreateWnd". A very confusing behaviour.
I did not test this, but I am sure that the button in the object tree will lead to the same issue.
I'd rather provide separate properties for those button properties you would allow the user to change. Like you do it with "ButtonCaption".
Some few other remarks about what stroke my eyes:
- I'd remove FButton.SetSubComponent from Create because as a TCustomPanel descendant the component already knows that all child controls are subcomponents.
- Remove the overridden destructor. FButton is created with AOwner = self (=the component), and therefore, the component automatically takes care of destroying the button.
- You must also add an overridden DoOnResize method calling SetButtonPosition after inherited so that the button remains centered after resizing the control.
- Why is there a call to RegisterClass in the initialization section? Normally this is handled by the LCL itself.
- Using a panel as ancestor for your component has the risk that the user adds other controls which may interfere with the button. Is this intended? If not you could override ValidateInsert and inhibit insertion of any controls once FButton is in the Controls list of the panel.