unit uProg5;

interface

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

type
  TfProg5 = class(TForm)
    lbBal: TListBox;
    lbJobb: TListBox;
    Label1: TLabel;
    Label2: TLabel;
    bJobbra: TButton;
    bJobbraMind: TButton;
    bBalra: TButton;
    bBalraMind: TButton;
    bBezar: TButton;
    procedure FormCreate(Sender: TObject);
    procedure bBezarClick(Sender: TObject);
    Procedure KijeloltetViszi(Forras,Cel:TListBox);
    Procedure MindetViszi(Forras,Cel:TListBox);
    Procedure GombAllitas;
    procedure bJobbraClick(Sender: TObject);
    procedure bJobbraMindClick(Sender: TObject);
    procedure bBalraClick(Sender: TObject);
    procedure bBalraMindClick(Sender: TObject);
    procedure lbBalClick(Sender: TObject);
    procedure lbJobbClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  fProg5: TfProg5;

implementation

{$R *.DFM}

procedure TfProg5.FormCreate(Sender: TObject);
Var i:Integer;
begin
    For i:=1 To 5 Do
       lbBal.Items.Add(IntToStr(i)+'. elem');
end;

procedure TfProg5.bBezarClick(Sender: TObject);
begin
Close;
end;

Procedure TfProg5.KijeloltetViszi(Forras,Cel:TListBox);
Var i:Integer;
Begin
   For i:=Forras.Items.Count-1 DownTo 0 Do
       If Forras.Selected[i] Then
          Begin
          Cel.Items.Add(Forras.Items[i]);
          Forras.Items.Delete(i);
          End;
   GombAllitas;
End;

Procedure TfProg5.MindetViszi(Forras,Cel:TListBox);
Var i:Integer;
Begin
   For i:=Forras.Items.Count-1 DownTo 0 Do
          Begin
          Cel.Items.Add(Forras.Items[i]);
          Forras.Items.Delete(i);
          End;
   GombAllitas;       
End;

Procedure TfProg5.GombAllitas;
Begin
   bJobbra.Enabled := lbBal.SelCount > 0;
   bJobbraMind.Enabled := lbBal.Items.Count > 0;
   bBalra.Enabled := lbJobb.SelCount > 0;
   bBalraMind.Enabled := lbJobb.Items.Count > 0;
End;

procedure TfProg5.bJobbraClick(Sender: TObject);
begin
KijeloltetViszi(lbBal,lbJobb);
end;

procedure TfProg5.bJobbraMindClick(Sender: TObject);
begin
MindetViszi(lbBal,lbJobb);
end;

procedure TfProg5.bBalraClick(Sender: TObject);
begin
KijeloltetViszi(lbJobb,lbBal);
end;

procedure TfProg5.bBalraMindClick(Sender: TObject);
begin
MindetViszi(lbJobb,lbBal);
end;

procedure TfProg5.lbBalClick(Sender: TObject);
begin
GombAllitas;
end;

procedure TfProg5.lbJobbClick(Sender: TObject);
begin
GombAllitas;
end;

end.
