unit labeledlistbox;
interface
uses Controls, stdctrls, ExtCtrls, Classes;
procedure Register;
implementation
type
TMyListBox =
Class( TCustomPanel )
private
FLabel: TLabel;
FListBox: TListBox;
procedure SetLabelCaption(
const Value:
String);
function GetLabelCaption:
String;
function GetListBoxItems: TStrings;
function GetListBoxItemIndex: Integer;
function GetListBoxOnClick: TNotifyEvent;
procedure SetListBoxItemIndex(
const Value: Integer);
procedure SetListBoxOnCLick(
const Value: TNotifyEvent);
public
constructor Create( AOwner: TComponent );
override;
destructor Destroy;
override;
published
property Font;
property LabelCaption:
String read GetLabelCaption
write SetLabelCaption;
property ListBoxItems: TStrings
read GetListBoxItems;
property ListBoxItemIndex: Integer
read GetListBoxItemIndex
write SetListBoxItemIndex;
property ListBoxOnClick: TNotifyEvent
read GetListBoxOnClick
write SetListBoxOnCLick;
end;
constructor TMyListBox.Create(AOwner: TComponent);
begin
inherited Create( AOwner );
FLabel := TLabel.Create( Self );
FLabel.Parent := Self;
FLabel.Align := alTop;
FLabel.Caption := '
LABEL_CAPTION';
FListBox := TListBox.Create( Self );
FListBox.PArent := Self;
FListBox.Align := alClient;
end;
destructor TMyListBox.Destroy;
begin
FLabel.Free;
FListBox.Free;
inherited Destroy;
end;
function TMyListBox.GetLabelCaption:
String;
begin
Result := FLabel.Caption;
end;
function TMyListBox.GetListBoxItemIndex: Integer;
begin
Result := FListBox.ItemIndex;
end;
function TMyListBox.GetListBoxItems: TStrings;
begin
Result := FListBox.Items;
end;
function TMyListBox.GetListBoxOnClick: TNotifyEvent;
begin
Result := FListBox.OnClick;
end;
procedure TMyListBox.SetLabelCaption(
const Value:
String);
begin
if FLabel.Caption <> Value
then
begin
FLabel.Caption := Value;
Invalidate;
end;
end;
procedure TMyListBox.SetListBoxItemIndex(
const Value: Integer);
begin
if FListBox.ItemIndex <> Value
then
begin
FListBox.ItemIndex := Value;
Invalidate;
end;
end;
procedure TMyListBox.SetListBoxOnCLick(
const Value: TNotifyEvent);
begin
FListBox.OnClick := Value;
end;
procedure Register;
begin
RegisterComponents('
Additional', [TMyListBox]);
end;
end.