Solved

How to trap EInOutError exception?

Posted on 2002-05-01
11
713 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

867 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

15 Experts available now in Live!

Get 1:1 Help Now