?
Solved

problem with DriveComboBox

Posted on 1999-01-18
5
Medium Priority
?
981 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 80 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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month8 days, 15 hours left to enroll

764 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