Determining if a drive is ready
   


It's sometimes a good idea to check if a drive is ready before accessing it. Such a good case is the floppy drive. DiskInDrive() will check for the availability of the drive without those ugly Windows error messages. Pass the drive number to the function (you can use the GetDriveNumber() function to get the drive's number).

function DiskInDrive(DriveNumber: integer): boolean;
{ func to determine if a drive is ready or available. }
var
  ErrorMode: word;
begin
  { turn off critical errors }
  ErrorMode := SetErrorMode(SEM_FailCriticalErrors);
  try
    { drive 1 = a, 2 = b, 3 = c, etc. }
    Result := DiskSize(DriveNumber) <> -1;
  finally
    { restore old error mode }
    SetErrorMode(ErrorMode);
  end;
end;


Blue Orb Software

[email protected]