unit Unit2;

{$mode objfpc}{$H+}

interface

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

type

  { TForm2 }

  TForm2 = class(TForm)
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    BitBtn3: TBitBtn;
    Button1: TButton;
    Button2: TButton;
    ListBox1: TListBox;
    OpenDialog1: TOpenDialog;
    Panel1: TPanel;
    SelectDirectoryDialog1: TSelectDirectoryDialog;
    procedure BitBtn1Click(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);
    procedure BitBtn3Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure FormActivate(Sender: TObject);
  private

  public

  end;

var
  Form2: TForm2;

implementation
 uses Unit1;
{$R *.lfm}

{ TForm2 }

procedure TForm2.BitBtn1Click(Sender: TObject);
var fullFileName, FileName, dir : String;
begin
     dir := ExtractFileDir(Unit1.fullFileName);
    OpenDialog1.InitialDir:=dir;
    if OpenDialog1.Execute then
  begin
   fullFileName := OpenDialog1.FileName;
   FileName := ExtractFileName(fullFileName);
   ListBox1.Items.Add(FileName);
  end;
end;

procedure TForm2.BitBtn2Click(Sender: TObject);
var fullFileName, FileName, dir: String;
begin
    dir := ExtractFileDir(Unit1.fullFileName);
    SelectDirectoryDialog1.InitialDir:=dir;
    if SelectDirectoryDialog1.Execute then
  begin
   fullFileName := SelectDirectoryDialog1.FileName;
   FileName := ExtractFileName(fullFileName);
   ListBox1.Items.Add(FileName);
  end;

end;

procedure TForm2.BitBtn3Click(Sender: TObject);
begin
  close;
end;

procedure TForm2.Button1Click(Sender: TObject);
begin
  ListBox1.DeleteSelected;
end;

procedure TForm2.Button2Click(Sender: TObject);
begin
  ListBox1.Items.SaveToFile('file_dir.ini');
end;

procedure TForm2.FormActivate(Sender: TObject);
begin
  if FileExists('file_dir.ini') then ListBox1.Items.LoadFromFile('file_dir.ini');
end;

end.

