Solved

problem with DriveComboBox

Posted on 1999-01-18
5
973 Views
Last Modified: 2008-02-01

Hi experts,

I have a form with a DriveComboBox in my program. This ComboBox displays all drives on my PC (harddisk,floppy drive,cd-rom drive,
JAZ-drive)

If I try to select a file from the harddisk, everthing works perfectly. However if I try to select a file from
floppy disk/CD-ROM/JAZ-drive, this will cause a run-time error, if there is no medium inserted in the
floppy disk/CD-ROM/JAZ-drive.
(Delphi says: "exception of class ElnOutError. I/O error 21.

How can I work around this problem? Can you please show me a sample source code which fixes this problem?

With kind regards

Mathes

0
Comment
Question by:mathes
  • 2
  • 2
5 Comments
 
LVL 1

Expert Comment

by:martin_g
ID: 1362355
It's not great but will probably work!

Include an exception handler such as

procedure TForm1.DriveComboBox1Change(Sender: TObject);
begin
try

except on EINOUTError do
  ShowMessage('Drive not available');
  end;
end;
0
 
LVL 3

Accepted Solution

by:
philipleighs earned 20 total points
ID: 1362356
Here is one way of dealing with this.

Make sure that the DirList property is empty.
In the Drive combo change event type this:

procedure TForm1.DriveComboBox1Change(Sender: TObject);
  begin
    if DiskFree(Ord(UpCase(DriveComboBox1.Drive)) - Ord('A') + 1) <> -1 then
      begin
        //This drive is ready.
        DirectoryListBox1.Drive := DriveComboBox1.Drive;
      end
    else
      begin
        //The drive is not ready, so set the drive back to
        //what we started with.
        ShowMessage('drive not ready');
        DriveComboBox1.Drive := DirectoryListBox1.Drive;
      end;
  end;

//DiskFree is used to determine if the drive is ready. It returns -1 if not.

Cheers,
Phil.

0
 

Author Comment

by:mathes
ID: 1362357

Dear Phil,

thank you for your feedback. Can you please tell me, how I can empty
the DirList property. Whenever I tried your routine in my sample code, the
DirListbox was never empty and therefore I got a runtime error.

With kind regards

Mathes


 

0
 
LVL 3

Expert Comment

by:philipleighs
ID: 1362358
Real easy, in the designer click the DriveCombo component, open object inspector, click the DirList property and press Delete, Enter. Now run the program!

Regards,
Phil.

0
 

Author Comment

by:mathes
ID: 1362359
Thank you for your help. This is exactly what I was looking for.

With kind regards

Mathes
0

Featured Post

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

823 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question