Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

problem with DriveComboBox

Posted on 1999-01-18
5
Medium Priority
?
983 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 October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. 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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
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

636 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