unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, FileCtrl;type
  TForm1 = class(TForm)
    DriveComboBox1: TDriveComboBox;
    DirectoryListBox1: TDirectoryListBox;
    procedure DriveComboBox1Change(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure DriveComboBox1Click(Sender: TObject);
  private
    { Private declarations }
    function DiskInDrive(Drive: Char): Boolean;
  public
    { Public declarations }
  end;var
  Form1: TForm1;implementation{$R *.dfm}
{ TForm1 }function TForm1.DiskInDrive(Drive: Char): Boolean;
var  ErrorMode: word;
begin
  //將字母轉為大寫
  if Drive in ['a'..'z'] then Dec(Drive, $20);
  //確認參數為字母
  if not (Drive in ['A'..'Z']) then
    raise EConvertError.Create('Not a valid drive ID');
  //觸發異常
  ErrorMode := SetErrorMode(SEM_FAILCRITICALERRORS);
  try
    if DiskSize(Ord(Drive) - $40) = -1 then
      Result := False
    else
      Result := True;
  finally
    SetErrorMode(ErrorMode);
  end;
end;procedure TForm1.DriveComboBox1Change(Sender: TObject);
label Retry;
begin
  //DriveComboBox1.OnChange := nil;//加入这行
  if not DiskInDrive(DriveComBoBox1.Drive) then
    begin
     Retry:
     if application.MessageBox(pchar('Windows无法读取驱动器'+DriveComboBox1.Drive+':。请确认驱动器已关闭,软盘已格式化而且无误。'),pchar('选择驱动器!'),MB_RETRYCANCEL+MB_ICONEXCLAMATION)=id_REtry then
     begin
       sleep(1000);
       goto Retry;
     end;
    end
  else
    begin
      DriveComboBox1.DirList:=DirectoryListBox1;
    end; 
end;procedure TForm1.FormCreate(Sender: TObject);
begin
  DriveComboBox1.OnChange := nil;//加入这行
end;procedure TForm1.FormShow(Sender: TObject);
begin
  DriveComboBox1.OnChange:=Form1.DriveComboBox1Change;
end;procedure TForm1.DriveComboBox1Click(Sender: TObject);
begin
  DriveComboBox1.OnChange := Form1.DriveComboBox1Change;
end;
end.

解决方案 »

  1.   

    给你个检查软盘是否Ready的函数function DisketteDriveReady (DisketteDrive: char):int64;
    var
       Drive: byte;
       PrevInt24: word;
    begin
       case DisketteDrive of
         'A', 'a':  Drive := 1;
         'B', 'b':  Drive := 2;
       else
          begin
             Result:=-1;
             Exit;
          end;
       end;
       PrevInt24 := SetErrorMode(SEM_FAILCRITICALERRORS);
       Result:=DiskFree(Drive);
       SetErrorMode(PrevInt24);
    end;function FloppyDiskExists:int64;
    begin
       //函数返回值:-1不存在磁盘,其他为软盘空余空间。
       Result:=DiskettedriveReady('A');
    end;
      

  2.   

    catch 一下io 的exception 弹出showmessage提示就可以