在一个DriveListBox中, 如果A盘没有磁盘的话, 当你选择A盘的时候, 程序就会弹出一个错误显示, 该如何屏蔽该显示,或用自定义的显示内容显示出来?
用 try 结构好像不行.

解决方案 »

  1.   

    因为它是先于你的代码去判断的,你当然用TRY不能实现,你把DRVIVELISTBOX的源码给改一下
      

  2.   

    用TApplicationEvent 组件  OnException 里自己处理异常看看
      

  3.   

    ----------------------驱动器是否有盘function 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(Format('%S 不是有效的驱动器符号',[Drive]) );
    ErrorMode := SetErrorMode(SEM_FailCriticalErrors);
    try
    if DiskSize(Ord(Drive) - $40) = -1 then
    Result := False
    else
    Result := True;
    finally
    SetErrorMode(ErrorMode);
    end;
    end;------------------------调用procedure TForm1.BitBtn1Click(Sender: TObject);
    begin
    if not DiskInDrive('A') then
    showmessage('no disk in a');end;
      

  4.   

    Tools->Debug Options...->Language Exceptions勾去Stop on Delphi Exceptions再运行楼上代码