home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 October / Chip_2001-10_cd1.bin / zkuste / delphi / kompon / d56 / WAVFILE.ZIP / Main.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2001-07-31  |  2.7 KB  |  107 lines

  1. unit Main;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   StdCtrls, FileCtrl, ExtCtrls, WAVFile;
  8.  
  9. type
  10.   TMainForm = class(TForm)
  11.     DriveList: TDriveComboBox;
  12.     FolderList: TDirectoryListBox;
  13.     FileList: TFileListBox;
  14.     CloseButton: TButton;
  15.     InfoBevel: TBevel;
  16.     IconImage: TImage;
  17.     ValidHeaderLabel: TLabel;
  18.     FileSizeLabel: TLabel;
  19.     ValidHeaderText: TEdit;
  20.     ChannelModeText: TEdit;
  21.     ChannelModeLabel: TLabel;
  22.     SampleRateLabel: TLabel;
  23.     BitsPerSampleLabel: TLabel;
  24.     DurationLabel: TLabel;
  25.     SampleRateText: TEdit;
  26.     BitsPerSampleText: TEdit;
  27.     DurationText: TEdit;
  28.     FileSizeText: TEdit;
  29.     procedure CloseButtonClick(Sender: TObject);
  30.     procedure FormCreate(Sender: TObject);
  31.     procedure FileListChange(Sender: TObject);
  32.     procedure FormClose(Sender: TObject; var Action: TCloseAction);
  33.   private
  34.     { Private declarations }
  35.     WAVFile: TWAVFile;
  36.     procedure ClearAll;
  37.   end;
  38.  
  39. var
  40.   MainForm: TMainForm;
  41.  
  42. implementation
  43.  
  44. {$R *.dfm}
  45.  
  46. procedure TMainForm.ClearAll;
  47. begin
  48.   { Clear all captions }
  49.   ValidHeaderText.Text := '';
  50.   ChannelModeText.Text := '';
  51.   SampleRateText.Text := '';
  52.   BitsPerSampleText.Text := '';
  53.   FileSizeText.Text := '';
  54.   DurationText.Text := '';
  55. end;
  56.  
  57. procedure TMainForm.CloseButtonClick(Sender: TObject);
  58. begin
  59.   { Exit }
  60.   Close;
  61. end;
  62.  
  63. procedure TMainForm.FormCreate(Sender: TObject);
  64. begin
  65.   { Create object }
  66.   WAVFile := TWAVFile.Create;
  67.   { Reset captions }
  68.   ClearAll;
  69. end;
  70.  
  71. procedure TMainForm.FileListChange(Sender: TObject);
  72. begin
  73.   { Clear captions }
  74.   ClearAll;
  75.   if FileList.FileName = '' then exit;
  76.   if FileExists(FileList.FileName) then
  77.     { Load WAV header }
  78.     if WAVFile.ReadFromFile(FileList.FileName) then
  79.       if WAVFile.Valid then
  80.       begin
  81.         { Fill captions }
  82.         ValidHeaderText.Text := 'Yes';
  83.         ChannelModeText.Text := WAVFile.ChannelMode;
  84.         SampleRateText.Text := IntToStr(WAVFile.SampleRate) + ' hz';
  85.         BitsPerSampleText.Text := IntToStr(WAVFile.BitsPerSample) + ' bit';
  86.         FileSizeText.Text := IntToStr(WAVFile.FileSize) + ' bytes';
  87.         DurationText.Text := FormatFloat('.000', WAVFile.Duration) + ' sec.'; 
  88.       end
  89.       else
  90.         { Header not found }
  91.         ValidHeaderText.Text := 'No'
  92.     else
  93.       { Read error }
  94.       ShowMessage('Can not read header in the file: ' + FileList.FileName)
  95.   else
  96.     { File does not exist }
  97.     ShowMessage('The file does not exist: ' + FileList.FileName);
  98. end;
  99.  
  100. procedure TMainForm.FormClose(Sender: TObject; var Action: TCloseAction);
  101. begin
  102.   { Free memory }
  103.   WAVFile.Free;
  104. end;
  105.  
  106. end.
  107.