Frequently Asked Questions
Detecting if there's a disk in a drive
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;