Solved

How to trap EInOutError exception?

Posted on 2002-05-01
11
712 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
Comment Utility
Something like this

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


The Crazy One
0
 
LVL 4

Expert Comment

by:jsweby
Comment Utility
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
Comment Utility
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
 

Expert Comment

by:W_Fox
Comment Utility
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
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 44

Expert Comment

by:CrazyOne
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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 150 total points
Comment Utility
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
Comment Utility
That was it LoneA !

That was exactly what I needed.

Thaks a lot !

Cheers,


AJ
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

763 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

11 Experts available now in Live!

Get 1:1 Help Now