Function AudioCD(Drive : Char) : Boolean; 
Var 
FSFlags, MaxLength: DWORD; 
VolName, Path : String; 
Begin 
     Path := Drive + ':\'; 
     Result := FALSE; 
     if (GetDriveType(PChar(Path)) = DRIVE_CDROM) then 
             Begin 
SetLength(VolName, 64); 
GetVolumeInformation(PChar(Path), PChar(VolName), Length(VolName), nil, MaxLength, FSFlags, nil,0); 
if (lStrCmp(PChar(VolName),'Audio CD') = 0) Then Result := TRUE; 
            End; 
end; 

解决方案 »

  1.   

    拦截消息WM_DEVICECHANGE即可! //响应该消息 procedure Tform1.WMDEVICECHANGE(var msgx :Tmessage); const DBT_DEVICEARRIVAL=$8000; DBT_DEVICEREMOVECOMPLETE=$8004; begin inherited; case msgx.WParam of DBT_DEVICEARRIVAL:Caption :='有了!'; DBT_DEVICEREMOVECOMPLETE:Caption :='取走了'; end; end;
    什么拦截?
      

  2.   

    你可以引入File Object System对象,通过Drive对象的IsReady属性判断驱动器状态。
      

  3.   

    procedure TFrmpfljwjm.HandleMyException(Sender: TObject; E: Exception);
    begin
      if (E.ClassType.ClassName='EInOutError') then
      begin
        {do something great to (or for) the user}
        MessageBox( Handle,'设备尚未准备好','错误',MB_OK or MB_ICONERROR);
      end
      else Application.ShowException(E); {let Delphi take it from here}
    end;
    这样就行了,,