Board index » delphi » Q: How to stop the "drive a not ready" message

Q: How to stop the "drive a not ready" message

spi...@diku.dk (Kim Vagn Jakobsen) wrote:

Quote
>Hello.
>I have just started programming in delphi, and have seen a problem
>i do not understand.
>In my old pascal programs, you can avoid I/O errors by using
>the {$I-} directive. I use this to test if there is a disk in
>drive a (i try tp create a file). If i do this in delphi, there
>pops up a window, stating that drive a is not ready, or something like
>that. My program doesn't crash, and IOResult returns the right error
>code. How can i avoid this window ?
>thanks in advance
>  Kim (spi...@diku.dk)
>--
>http://www.diku.dk/students/spiril/
>"Sometimes I think the surest sign that intelligent life exists elsewhere in
>the universe is that none of it has tried to contact us"

This is a message from Scott Hembrough along time ago that I saved...
it answers your question:

-----------------
Hi everyone!

I am new to the world of Delphi and the Windows API,
so I was pretty e{*word*277}d when I stumbled across the
solution to a problem that has been plaguing me for
weeks!!!  I thought I'd post it in case someone else
is struggling with the same problem.

BACKGROUND:  I am writing an application that reports
various statistics about a PC.  Included in these
statistics is a listing of the total capacity of
system disk drives and total free space of these disk drives.  

ORIGINAL PROBLEM:  Whenever I tried to report the size of
a floppy or cd-rom drive that was empty, I received a
system modal dialog from windows stating that my drive
was not ready or not working properly.  Exception handling
would not handle this error...  Windows was taking control
immediately after I accessed the drive.

INITIAL REACTION:  Confusion and frustration... until I
found the SetErrorMode API function.

SOLUTION:  Call the SetErrorMode Windows API function
(available in the WinProcs unit in Delphi).  

To quote the Windows API Help file directly, "The SetErrorMode
function controls whether Windows handles MS-DOS Interrupt 24h
errors or allows the calling application to handle them."

To rephrase this in plain english, this function allows you take
control of error handling that would normally be done
automatically by Windows.  For my particular program, I
made the following call...

SetErrorMode(SEM_FAILCRITICALERRORS);

The SEM_FAILCRITICALERRORS function basically tells Windows not
to display the "critical-error-handler" message box when
accessing an empty drive -- just return the error to the calling
application.

As a result, I am now able to proceed normally as I loop
through all of the available drives on my system -- even
if they don't contain a disk.

CONCLUSION:  I can now sleep at night knowing that this is
no longer a problem ;)

Hope this helps somebody!!!

Scott

--------------------------

Hope this helps...
Brien King
bk...@primenet.com

 

Re:Q: How to stop the "drive a not ready" message


Hello.

I have just started programming in delphi, and have seen a problem
i do not understand.

In my old pascal programs, you can avoid I/O errors by using
the {$I-} directive. I use this to test if there is a disk in
drive a (i try tp create a file). If i do this in delphi, there
pops up a window, stating that drive a is not ready, or something like
that. My program doesn't crash, and IOResult returns the right error
code. How can i avoid this window ?

thanks in advance
  Kim (spi...@diku.dk)

--
http://www.diku.dk/students/spiril/

"Sometimes I think the surest sign that intelligent life exists elsewhere in
the universe is that none of it has tried to contact us"

Re:Q: How to stop the "drive a not ready" message


Kim Vagn Jakobsen (spi...@diku.dk) wrote:
: Hello.

: I have just started programming in delphi, and have seen a problem
: i do not understand.

: In my old pascal programs, you can avoid I/O errors by using
: the {$I-} directive. I use this to test if there is a disk in
: drive a (i try tp create a file). If i do this in delphi, there
: pops up a window, stating that drive a is not ready, or something like
: that. My program doesn't crash, and IOResult returns the right error
: code. How can i avoid this window ?

Try:

Function DiskInDrive : Boolean;
Begin
  ($I-)
  ChDir('A:\');
  ($I+)
  If (IOResult = 0) Then DiskInDrive := True
    Else DiskInDrive := False;
End;

Other Threads