求助如何在程序中判断软驱中是否有盘!(30分)

  • 主题发起人 主题发起人 FlyAway
  • 开始时间 开始时间
F

FlyAway

Unregistered / Unconfirmed
GUEST, unregistred user!
求助如何在程序中判断软驱中是否有盘!<br>谢谢!
 
最简单的方法是取软驱中盘片的容量,没容量也就没盘了<br>ex:<br>procedure xxx<br>var<br>driver:pchar;<br>sec1, byt1, cl1, cl2:longword;<br>begin<br>driver:='a:/';//要显示的驱动器名<br>try<br>GetDiskFreeSpace(driver, sec1, byt1, cl1, cl2);<br>cl1 := cl1 * sec1 * byt1; 该驱动器总共容量<br>cl2 := cl2 * sec1 * byt1; 该驱动器可用容量<br>if cl1&gt;0 then showmessage('have a disk!');<br>finally<br>&nbsp; showmessage('no drive or no disk);<br>end;<br>
 
这是个土方法。<br>在dos 下 int13h可以检测到,但是在windows 下不推进用了,尤其在nt下是不能用了。<br>我估计可能还有这方面的api,谁要知道告诉我一声<br>var<br>&nbsp; ErrorCode: integer;<br>begin<br>&nbsp; try<br>&nbsp; &nbsp; Mkdir('a:/ttttssss');<br>&nbsp; &nbsp; rmdir('a:/ttttssss');<br>&nbsp; except<br>&nbsp; &nbsp; ErrorCode:= GetLastError;<br>&nbsp; &nbsp; case ErrorCode of<br>&nbsp; &nbsp; &nbsp; 19: &nbsp; &nbsp;ShowMessage('磁盘写保护! 19' );<br>&nbsp; &nbsp; &nbsp; 21: &nbsp; &nbsp;ShowMessage('没有软盘或者软驱未准备好!' );<br>&nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; ShowMessage('不知道!'+ IntToStr(ErrorCode));<br>&nbsp; &nbsp; end;<br>&nbsp; end;<br>end;<br>
 
给介函数。<br>function DiskInDrive(Drive: Char): Boolean;<br>var<br>&nbsp; &nbsp;ErrorMode: word;<br>begin<br>if Drive in ['a'..'z'] then<br>&nbsp; &nbsp;Dec(Drive, $20);<br>if not (Drive in ['A'..'Z']) then<br>&nbsp; &nbsp;raise EConvertError.Create(Format('%S 不是有效的驱动器符号',[Drive]) );<br>ErrorMode := SetErrorMode(SEM_FailCriticalErrors);<br>try<br>&nbsp; &nbsp; if DiskSize(Ord(Drive) - $40) = -1 then<br>&nbsp; &nbsp; &nbsp; Result := False<br>&nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; Result := True;<br>finally<br>&nbsp; &nbsp; &nbsp; SetErrorMode(ErrorMode);<br>end;<br>end;<br><br>例子<br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br>if not DiskInDrive('A') then<br>&nbsp; &nbsp; &nbsp; showmessage('no disk in a');<br>end;<br><br>
 
你可以尝试读软盘<br>用"try"语句<br>接收到系统的“异常”后(“异常”名可从delphi5的错误提示中找到 一般以“E”开头)<br>可判断 软驱没盘/软盘不能用 &nbsp;再做相应的处理<br><br>
 
谢谢大家,请教如何调用API实现?
 
多人接受答案了。
 
后退
顶部