procedure TForm1.btn1Click(Sender: TObject);
begin
        ds1.Filtered:=false;
        if(trim(edt1.Text)='') then
        begin
          ShowMessage('please input the condition!');
          edt1.SetFocus;
        end;
        ds1.Filter:=edt1.text;
        try
          ds1.Filtered:=true;
        except
          ShowMessage('input right condition!');
        end;end;
想问下大家为什么没有办法捕捉到输入筛选条件错误的异常呢?Delphi5+升级包

解决方案 »

  1.   

    如果随便输入一个fd字符的话就会跳出个错误对话框
    Project Project1.exe raised exception class EDataBaseError with message 'ds1:Field 'fd' not found'.Process Stoped.
    然后点击F9继续运行会显示对话框
    'input right condition!'
    感觉是捕捉到了,但是是异常已经抛出来再捕捉到的
    不知道这算不算正常情况,刚接触这方面的知识,觉得应该是不显示第一个对话框直接显示第二个对话框才对
      

  2.   

    如果这样的话有没有办法让第一个对话框不出现而直接出现代码中的showmessage对话框啊?
      

  3.   

    在单步执行时会出现Project Project1.exe raised exception class EDataBaseError with message 'ds1:Field 'fd' not found'.Process Stoped.
    这种情况
    编译后执行exe文件 不会出现此种情况 直接显示'input right condition!'
      

  4.   

    procedure TForm1.btn1Click(Sender: TObject);
    begin
      ds1.Filtered:=false;
      if(trim(edt1.Text)='') then
      begin
      ShowMessage('please input the condition!');
      edt1.SetFocus;
      exit;//不加这个就会继续执行下去的
      end;
      ds1.Filter:=edt1.text;//不加exit;如果trim(edt1.Text)=''这里就变成了ds1.Filter:='';当然不会报异常
      try
      ds1.Filtered:=true;
      except
      ShowMessage('input right condition!');
      end;
      

  5.   

    因为在IDE中调试,异常会被Delphi捕获~~~~