Title: The function DiskInDrive
Question: How to check if there is a disk inside the drive (or a cd-rom):
Answer:
The function SetErrorMode is switching of the system-messages that
are not 'beautiful' when accessing a disk-drive without a disk
inside.
function DiskInDrive(lw: Char ): integer;
var
sRec: TSearchRec;
res: integer;
begin
Result:= 0;
SetErrorMode(SEM_FAILCRITICALERRORS);
result := False;
{$I-}
res := FindFirst(lw + ':\*.*', faAnyfile, SRec );
FindClose(SRec);
{$I+}
case res of
0 : Result := 0;
2,18 : Result := 1;
21,3 : Result := 2;
else
Result := res;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
x: integer;
begin
x := DiskInDrive('a');
case x of
0: ShowMessage('Disk is there !');
1: ShowMessage('Disk is empty !');
2: ShowMessage('No disk in drive !');
else
ShowMessage('Disk not formatted !');
end; //case
end;