interface
uses
math,
System.SysUtils,
System.Classes,
VCL.Controls,
VCL.StdCtrls;
type
[ComponentPlatformsAttribute(pidWin32
or pidWin64)]
TListBoxEXT =
class(TListBox)
private
FLabel: TLabel;
// Label associated with the ListBox
FDeltaY: Integer;
public
constructor Create(AOwner: TComponent);
overload;
// Default constructor
constructor Create(AOwner: TComponent;
const LabelName:
String;
XPos, YPos: Integer);
overload;
// Overloaded constructor
constructor Create(AOwner: TComponent;
const LabelName:
String;
XPos, YPos, Width, Height: Integer);
overload;
destructor Destroy;
override;
// Accessor for the associated label
property LabelControl: TLabel
read FLabel;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('
TOOLS', [TListBoxEXT]);
end;
{ TListBoxEXT }
constructor TListBoxEXT.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
// Call the base class constructor
self.Parent := TWinControl(AOwner);
FLabel :=
nil;
// No label by default
end;
constructor TListBoxEXT.Create(AOwner: TComponent;
const LabelName:
String;
XPos, YPos, Width, Height: Integer);
begin
Create(AOwner, LabelName, XPos, YPos);
self.Width := Width;
self.Height := Height;
end;
constructor TListBoxEXT.Create(AOwner: TComponent;
const LabelName:
String;
XPos, YPos: Integer);
begin
inherited Create(AOwner);
// Call the base class constructor
FDeltaY := -20;
// Create and configure the label
FLabel := TLabel.Create(AOwner);
FLabel.Parent := TWinControl(AOwner);
// Assign the label's Parent to the same Parent
FLabel.Caption := LabelName;
FLabel.Left := XPos;
FLabel.Top := Max( YPos + FDeltaY,1);
// Position the ListBox below the label
self.Left := XPos;
self.Top := YPos;
// Add a small gap between the label and the ListBox
end;
destructor TListBoxEXT.Destroy;
begin
if Assigned(FLabel)
then
FLabel.Free;
// Free the label if it exists
inherited;
// Call the base destructor
end;
end.