?
Solved

How to trap EInOutError exception?

Posted on 2002-05-01
11
Medium Priority
?
726 Views
Last Modified: 2007-12-19
I have a DriveComboBox with a DirectoryListBox and a FileListBox on a form.

When I change the drive to D: (with no media int it) I get the standard system message. I want to trap the exception and display my own message not the system's.

Where should I write the try..except to do that?

Thanks a lot !

AJ
0
Comment
Question by:ajgonzalezm
  • 4
  • 3
  • 2
  • +2
11 Comments
 
LVL 44

Expert Comment

by:CrazyOne
ID: 6985297
Something like this

  try
  except
    on E: EInOutError do begin
      CodeForItHere;
    end;
  end;


The Crazy One
0
 
LVL 4

Expert Comment

by:jsweby
ID: 6985841
If you use the SetErrorMode API call with the SEM_FAILCRITICALERRORS parameter then Windows will not report the error if there is no media in a floppy drive or a CD-ROM drive.

e.g.
var
   OldErrorMode: Integer;
begin
     OldErrorMode := SetErrorMode(SEM_FAILCRITICALERRORS);
end;

SetErrorMode returns the previous error mode so if you keep it, as you should, when you are finished you can set the error mode back to how it was before you changed it.

J.
0
 

Author Comment

by:ajgonzalezm
ID: 6985986
CrazyOne:

I've already tried that piece of code in the OnChange event for the DiveComboBox but didn't work. Someone is taking the exception even before the 'try' gets executed.

Any other idea?

Thank you !

AJ
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Expert Comment

by:W_Fox
ID: 6986702
What about
{$I-}
 //your dangerous code here
{$I+}
if IOResult<>0 then messagebox(0,'Almost crashed the system...','Application',mb_ok+mb_taskmodal+mb_iconexclamation);
 

Haven't verified that, but maybe it works :)

W_Fox
0
 

Author Comment

by:ajgonzalezm
ID: 6991302
W Fox:

The problem is that I DO NOT have 'dangerous code' because the error is produced by a control (DriveComboBox) when I select a drive that is not available or has no media in it. So the question is WHERE should I put the code to trap the error. I've already tried in the OnChange event for the DriveComboBox but it didn´t work.

Any further help will be greatly apreciated.

Regards,


AJ

0
 
LVL 44

Expert Comment

by:CrazyOne
ID: 6992812
Try putting it where the change takes place. For example if Double Clicking causes the change then try it in the OnDblClick event.
         
0
 
LVL 1

Expert Comment

by:LoneA
ID: 6993099
Hi ajgonzalezm

I've experienced the the same problem as you have.

I used another drive-combobox-component instead - the one sold by Turbo Power (in the Orpheus-package) works.

... but I don't know if this is an option for you.

LoneA

0
 
LVL 1

Expert Comment

by:LoneA
ID: 6993140
Hi ajgonzalezm

I did a little thinking - and an experiment.

Actually - this works - i've just tried it !

procedure TForm1.DriveComboBoxChange(Sender: TObject);
VAR
  Drevet : String;
begin
  try
    DirectoryListBox.Drive := DriveComboBox.Drive;
  except
    on EInOutError do
    begin
      ShowMessage ('Show your own error message !');
  end;
end;
0
 

Author Comment

by:ajgonzalezm
ID: 6996953
LoneA:

I've just 'cuted and pasted' your suggested code but it didn't work. I still get 'I/O error 21' and the custom message never gets displayed.

What is 'Drevet : String' for? You never use it.

Thanks a lot.

AJ
0
 
LVL 1

Accepted Solution

by:
LoneA earned 600 total points
ID: 7005375
Hi AJ

Sorry - I forgot to "tell the whole story".

The reason why you still get an I/O-error displayed, is because your DIRLIST-property on your drivecombobox is assigned - clear this property, and you will catch the I/O-error.

LoneA
0
 

Author Comment

by:ajgonzalezm
ID: 7010962
That was it LoneA !

That was exactly what I needed.

Thaks a lot !

Cheers,


AJ
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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…
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…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses
Course of the Month17 days, 12 hours left to enroll

830 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