Solved

How to trap EInOutError exception?

Posted on 2002-05-01
11
714 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
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

803 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