该段代码为检测驱动器是否就绪,其中A代表软驱function DiskInDrive(Drive: Char): Boolean; var ErrorMode: word; begin { make it upper case } if Drive in ['a'..'z'] then Dec(Drive, $20); { make sure it's a letter } if not (Drive in ['A'..'Z']) then raise EConvertError.Create('Not a valid drive ID'); { turn off critical errors } ErrorMode := SetErrorMode(SEM_FailCriticalErrors); try { drive 1 = a, 2 = b, 3 = c, etc. } if DiskSize(Ord(Drive) - $40) = -1 then Result := Falseelse Result := True; finally { restore old error mode } SetErrorMode(ErrorMode); end; end;
我一直用这段代码://返回true软驱里是否有软盘,false没有 function TestFDriver:Boolean; var pres:UINT; pvol:array [0..128] of char; vols,maxcl,fsf:DWORD; begin pres := SetErrorMode(SEM_FAILCRITICALERRORS); try maxcl := 0; fsf := 0; Result := GetVolumeInformation('a:\',pvol,sizeof(pvol)-1,@vols,maxcl,fsf,nil,0) finally SetErrorMode(pres); end; end;
var ErrorMode: word;
begin
{ make it upper case }
if Drive in ['a'..'z'] then Dec(Drive, $20);
{ make sure it's a letter }
if not (Drive in ['A'..'Z']) then
raise EConvertError.Create('Not a valid drive ID');
{ turn off critical errors }
ErrorMode := SetErrorMode(SEM_FailCriticalErrors);
try
{ drive 1 = a, 2 = b, 3 = c, etc. }
if DiskSize(Ord(Drive) - $40) = -1 then
Result := Falseelse
Result := True;
finally
{ restore old error mode }
SetErrorMode(ErrorMode);
end;
end;
function TestFDriver:Boolean;
var
pres:UINT;
pvol:array [0..128] of char;
vols,maxcl,fsf:DWORD;
begin
pres := SetErrorMode(SEM_FAILCRITICALERRORS);
try
maxcl := 0;
fsf := 0;
Result := GetVolumeInformation('a:\',pvol,sizeof(pvol)-1,@vols,maxcl,fsf,nil,0)
finally
SetErrorMode(pres);
end;
end;