I want to create a custom control that contains several "panels" as sub-controls. It should be possible to add other controls such as buttons to those sub-control-panels.
So far, I have the following code:
unit ContainerTest;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs;
type
TContainerTestSide = class(TCustomControl)
public
constructor Create(TheOwner: TComponent); override;
destructor Destroy; override;
end;
TContainerTest = class(TCustomControl)
private
FSideA, FSideB: TContainerTestSide;
public
constructor Create(TheOwner: TComponent); override;
destructor Destroy; override;
published
property Anchors;
property AutoSize;
property Align default alNone;
property BorderSpacing;
property Visible;
property Constraints;
property OnMouseWheel;
property OnResize;
end;
procedure Register;
implementation
{ TContainerTestSide }
constructor TContainerTestSide.Create(TheOwner: TComponent);
begin
inherited Create(TheOwner);
ControlStyle := ControlStyle + [csAcceptsControls];
self.Color := clRed;
self.Width := 100;
self.Height := 200;
end;
destructor TContainerTestSide.Destroy;
begin
inherited Destroy;
end;
{ TContainerTest }
constructor TContainerTest.Create(TheOwner: TComponent);
begin
inherited Create(TheOwner);
ControlStyle := ControlStyle - [csAcceptsControls];
self.Width := 200;
self.Height := 200;
self.FSideA := TContainerTestSide.Create(self);
self.FSideA.Align := alLeft;
self.FSideA.SetSubComponent(true);
self.FSideA.Parent := self;
self.FSideB := TContainerTestSide.Create(self);
self.FSideB.Align := alRight;
self.FSideB.SetSubComponent(true);
self.FSideB.Parent := self;
end;
destructor TContainerTest.Destroy;
begin
self.FSideA.Free;
self.FSideB.Free;
inherited Destroy;
end;
procedure Register;
begin
{$I containertest_icon.lrs}
RegisterComponents('TestControls',[TContainerTest]);
RegisterNoIcon([TContainerTestSide]);
end;
end.
This code compiles well, the sub panels (FSideA and FSideB) are displayed at design time (I made them red to see that) and I can add controls to the sub panels at run-time.
However, the sub panels are not displayed in the object inspector and I can not add controls to them at design time.
How can I do that? Probably it's just some kind of flag or property I have to set (ControlStyle or so?). But I don't know. Can someone help me? Lazarus' TPairSplitter is behaving in a way, I want to have here, so there must be a way. But I could not figure out how it is done there when analyzing its code.