Solved

problem with DriveComboBox

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

840 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