#include <vcl.h>
#pragma hdrstop
#include "Unit09.h"
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//--------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//--------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
    DirectoryListBox1->FileList = FileListBox1;
    FilterComboBox1->Filter = "wszystkie pliki (*.*)|*.*|"
    "pliki (*.h;*.hpp)|*.h;*.hpp |pliki (*.cpp;*bpr)|*.cpp;*.bpr" ;

    DriveComboBox1->DirList = DirectoryListBox1;
    FileListBox1->FileEdit = Edit1;
    
    Memo1->ScrollBars = ssBoth;
}
//--------------------------------------------------------------------
void __fastcall TForm1::FilterComboBox1Change(TObject *Sender)
{
   FileListBox1->Mask = FilterComboBox1->Mask;
}
//--------------------------------------------------------------------
void __fastcall TForm1::FileListBox1Change(TObject *Sender)
{
  int iFileHandle;
  int iFileLength;
  char *Buffer;
    try {
      Memo1->Lines->Clear();
      iFileHandle = FileOpen(FileListBox1->FileName.c_str(), 
                             fmOpenRead);
      iFileLength = FileSeek(iFileHandle, 0, 2);
      FileSeek(iFileHandle, 0, 0);
      Buffer = new char[iFileLength+1];
      FileRead(iFileHandle, Buffer, iFileLength);
      FileClose(iFileHandle);
      Memo1->Lines->Append(Buffer);
      Form1->Caption = Edit1->Text;
      delete [] Buffer;
    }
    catch(...)
    {
     ShowMessage(" Błąd otwarcia pliku. Nie można przydzielić"
                 " wystarczającej ilości pamięci do wczytania" 
                 " pliku.");
    }

}
//--------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
    Application->Terminate();
}
//--------------------------------------------------------------------

