unit flistbox;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TfrmListBox = class(TForm)
    lblName: TLabel;
    txtName: TEdit;
    lstClient: TListBox;
    cmdAdd: TButton;
    cmdRemove: TButton;
    cmdClear: TButton;
    cmdClose: TButton;
    lblDisplay: TLabel;
    Label1: TLabel;
    procedure cmdAddClick(Sender: TObject);
    procedure cmdCloseClick(Sender: TObject);
    procedure cmdRemoveClick(Sender: TObject);
    procedure cmdClearClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmListBox: TfrmListBox;

implementation

{$R *.DFM}

procedure TfrmListBox.cmdAddClick(Sender: TObject);
begin
  lstClient.Items.Add (txtName.Text);
  txtName.Text := '';
  txtName.SetFocus;
  lblDisplay.Caption := IntToStr (lstClient.Items.Count);
  cmdRemove.Enabled := True;
end;

procedure TfrmListBox.cmdCloseClick(Sender: TObject);
begin
  Close;
end;

procedure TfrmListBox.cmdRemoveClick(Sender: TObject);
var
  Ind:Integer;
begin
  Ind := lstClient.ItemIndex;

  if Ind >= 0 then
  begin
    lstClient.Items.Delete (Ind);
    lblDisplay.Caption := IntToStr(lstClient.Items.Count);
  end
  else MessageBeep(0);

  if lstClient.Items.Count < 1 then cmdRemove.Enabled := False;
end;

procedure TfrmListBox.cmdClearClick(Sender: TObject);
begin
  lstClient.Clear;
  lblDisplay.Caption := IntToStr(lstClient.Items.Count);
end;

end.
