Solved

problem with DriveComboBox

Posted on 1999-01-18
5
972 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

757 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now