Board index » delphi » Detecting Drive Not Ready in DriveComboBox Change Event...

Detecting Drive Not Ready in DriveComboBox Change Event...

Hello All,

  I am using a DirectoryListBox/DriveComboBox pair to select a directory (for a
CD-ROM based application).  I get an exception in the following routine when I
select the CD-ROM with no CD in it.  How can I prevent this?  It occurs during
the assignment below.

procedure TForm1.DriveComboBox1Change(Sender: TObject);
begin
  DirectoryListBox1.Drive := DriveComboBox1.Drive;
end;

Thanks in advance for any help provided.

Tim Hiller

 

Re:Detecting Drive Not Ready in DriveComboBox Change Event...


Quote
> procedure TForm1.DriveComboBox1Change(Sender: TObject);
> begin
>   DirectoryListBox1.Drive := DriveComboBox1.Drive;
> end;

Do this:

procedure TForm1.DriveComboBox1Change(Sender: TObject);
begin
  try
    DirectoryListBox1.Drive := DriveComboBox1.Drive;
  except
    MessageDlg('The drive is not ready!',mtError,[mbOK],0);
  end;
end;

Stefan

Other Threads