Главная страница | назад





Article #18004: Detecting if there's a disk in a drive

 Question and Answer Database

FAQ3004D.txt   Detecting if there's a disk in a drive
Category   :Miscellaneous
Platform    :All
Product    :All 32 bit  

Question:
How do I detect if there's a disk in a drive? How do
I avoid the critical error box that Windows displays?


Answer:
Here's a short example:

  procedure TForm1.Button1Click(Sender: TObject);
  var
    OldErrorMode : Integer;
    fp           : TextFile;
  begin
    try
      OldErrorMode := SetErrorMode(SEM_FAILCRITICALERRORS);
      try
        AssignFile(fp,'A:\foo.bar');
        Reset(fp);
        CloseFile(fp);
      finally
        SetErrorMode(OldErrorMode);
      end;
    except
      on E:EInOutError do
        if E.ErrorCode = 21 then
          ShowMessage('Drive A: is not ready...');
    end;
  end;


7/16/98 4:31:28 PM
 

Last Modified: 01-SEP-99