If you have a custom component and you always want it to exist inside of a scrollbox then the cleanest solution would be to either update or extend that component to have its own scrollbox. Here is an example using a TLabel
, but you can replace it with whatever your custom component is.
unit MyScrollBox;
interface
uses
System.SysUtils, System.Classes, Vcl.Controls, Vcl.Forms, Vcl.StdCtrls;
type
TMyScrollComponent = class(TScrollBox)
private
FLabel : TLabel;
procedure SetLabelText(AText : string);
function GetLabelText : string;
protected
constructor Create(AOwner : TComponent); override;
published
property LabelText : string read GetLabelText write SetLabelText;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Samples', [TMyScrollComponent]);
end;
constructor TMyScrollComponent.Create(AOwner : TComponent);
begin
inherited;
FLabel := TLabel.Create(self);
FLabel.Parent := self;
FLabel.Caption := 'Hello From Scrollbox!';
end;
procedure TMyScrollComponent.SetLabelText(AText : string);
begin
FLabel.Caption := AText;
end;
function TMyScrollComponent.GetLabelText : string;
begin
result := FLabel.Caption;
end;
end.
This demonstrates a custom component that inherits from TScrollBox
, contains a TLabel
and exposes the Caption
property of the TLabel
through a custom published property. Following this pattern you can also expose whatever other properties of your custom control that you need, etc.
Alternatively, if you want to preserve the ability to make layout changes inside the scrollbox at designtime then another solution would be to make a custom TFrame
. Just add one to your project and, following a build, it becomes available in the tool pallette under Standard -> Frames
.