Solved

How to trap EInOutError exception?

Posted on 2002-05-01
11
717 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
[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
  • 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
Independent Software Vendors: 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 150 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

Technology Partners: 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!

Question has a verified solution.

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

Suggested Solutions

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…
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…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

734 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