unit frmDoListBox;

{$mode delphi}

interface

uses
  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls, Buttons;

type

  { TdlgDoListBox }

  TdlgDoListBox = class(TForm)
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    ListBox1: TListBox;
    Panel1: TPanel;
    lbNbElements: TStaticText;
  private

  public
    function  Initialiser(const QTitle: string; const QListeItems: TStrings): boolean;
    function  GetSelectedIndex(): integer;
    function  GetSelectedItem(): string;
  end;

var
  dlgDoListBox: TdlgDoListBox;

implementation

{$R *.lfm}

{ TdlgDoListBox }

function TdlgDoListBox.Initialiser(const QTitle: string; const QListeItems: TStrings): boolean;
var
  Nb: Integer;
begin
  result := false;
  try
    self.Caption := QTitle;
    Nb := QListeItems.Count;
    if (0 = Nb) then exit;
    ListBox1.Items.Assign(QListeItems);
    ListBox1.ItemIndex := 0;
    lbNbElements.Caption := format('%d items', [Nb]);
    result := true;
  except
  end;
end;

function TdlgDoListBox.GetSelectedIndex(): integer;
begin
  result := ListBox1.ItemIndex;
end;

function TdlgDoListBox.GetSelectedItem(): string;
begin
  result := ListBox1.Items[ListBox1.ItemIndex];
end;

end.

