/// unit zobrazujuci vyber priecinkov
unit opendir;

interface

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

type
  /// trieda na zobrazenie vyberu priecinkov
  TOpenDirForm = class(TForm)
    DirectoryListBox1: TDirectoryListBox;
    DriveComboBox1: TDriveComboBox;
    DirLabel1: TLabel;
    Button1: TButton;
    procedure FormShow(Sender: TObject);
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure Button1Click(Sender: TObject);
    procedure DriveComboBox1Change(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  OpenDirForm: TOpenDirForm;
  res: Integer;

implementation

{$R *.dfm}

/// procedura volana pri zmene comboboxu s vyberom diskov v systeme
procedure TOpenDirForm.DriveComboBox1Change(Sender: TObject);
begin
  try
    DirectoryListBox1.Drive := DriveComboBox1.Drive;
  except
    try
      DirectoryListBox1.Drive := 'c';
    except
      ModalResult := mrCancel;
      Button1.ModalResult := mrCancel;
      Hide;
    end;
  end;
end;

/// procedura spracuvavajuca stlacenie tlacidla open a zatvarajuca toto okno
procedure TOpenDirForm.Button1Click(Sender: TObject);
begin
  res := 1;
  ModalResult := mrOK;
  Hide;
end;

/// procedura volana tesne pred zatvorenim tohto okna
procedure TOpenDirForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  if res <> 1 then begin
    ModalResult := mrCancel;
    Button1.ModalResult := mrCancel;
//    Button1.Click;
  end;
//  ShowMessage('close');
end;

/// procedura volana pre zatvorenim tohto okna, zistujuca ci je mozne ho zatvorit
procedure TOpenDirForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
  CanClose := true;
end;

/// procedura volana tesne po zobrazeni okna
procedure TOpenDirForm.FormShow(Sender: TObject);
begin
  res := 0;
end;

end.
