I think that is a bug from the IDE ..
I tested this unit , and it's works as expected (using subcomponent ):
unit uMyPanel;
interface
uses
System.SysUtils, System.Classes,
Vcl.Controls, Vcl.ExtCtrls, WinApi.Messages;
type
TMyPanel = class(TPanel)
private
{ Private declarations }
FSubPanel: TPanel;
procedure WMWindowPosChanged(var Message: TWMWindowPosChanged);
message WM_WINDOWPOSCHANGED;
protected
{ Protected declarations }
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
{ Public declarations }
published
{ Published declarations }
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Samples', [TMyPanel]);
end;
{ TMyPanel }
const
FSubPanelHeight = 30;
constructor TMyPanel.Create(AOwner: TComponent);
begin
inherited;
FSubPanel := TPanel.Create(Self);
FSubPanel.Parent := Self;
FSubPanel.Width := Width;
FSubPanel.Height := FSubPanelHeight;
FSubPanel.Caption := 'Title';
FSubPanel.Color := $00F4EBE2;
FSubPanel.Font.Color := $00B68C59;
Caption := '';
ShowCaption := False;
Height := 100;
Color := $00F4EBE2;
end;
destructor TMyPanel.Destroy;
begin
if Assigned(FSubPanel) then
FSubPanel.Destroy;
inherited;
end;
procedure TMyPanel.WMWindowPosChanged(var Message: TWMWindowPosChanged);
begin
inherited;
FSubPanel.Width := Width;
end;
end.
if this Component TMyPanel
has the same problem in your delphi IDE .. then it's probably a bug ,since this Component was tested using XE3 and i have not experienced this problem .
Note : this is only a test .. you should do what @Sir Rufo suggested .