unit main;

{$mode objfpc}{$H+}

interface

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

type

  { TForm1 }

  TForm1 = class(TForm)
    btnAnadir: TButton;
    btnEliminar: TButton;
    btnCerrar: TButton;
    Label1: TLabel;
    edElemento: TLabeledEdit;
    lbOpciones: TListBox;
    procedure btnAnadirClick(Sender: TObject);
    procedure btnCerrarClick(Sender: TObject);
    procedure btnEliminarClick(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.lfm}

{ TForm1 }

procedure TForm1.btnAnadirClick(Sender: TObject);
begin
  if edElemento.Text = '' then
  begin
       edElemento.SetFocus;
       MessageDlg ('Es necesario un elemento', mtError, [mbOK], 0);
  end
  else
  begin

lbOpciones.Items.Add(edElemento.Text);
  edElemento.SelectAll;
  edElemento.SetFocus;
end;
  end;

procedure TForm1.btnCerrarClick(Sender: TObject);
begin
  Close;
end;

procedure TForm1.btnEliminarClick(Sender: TObject);
var
  i: Integer;
begin
  i := 0;
  with lbOpciones do
    while i < Items.Count do
    begin
      if Selected[i] then
      begin
        Items.Delete(i);
        i := 0;
      end
      else
        Inc(i);
    end;
edElemento.SetFocus;
end;

end.

