不会吧你在Except后面加一个Showmessage,把Onxxx注释一下,看看行不行
function chk_date_valid(str:string):boolean;
    begin
   try
        result:=true;
        StrToDateTime(str);
    except
            showmessage('Date Error'); 
            result:=false;
    end;
  end;

解决方案 »

  1.   

    附加一道题:
    如何自动获取错误的代码及错误代码信息?就VB一样智能型的
    在VB中只需要用它的ERR对象就能自动识别你程序错的原因(如:err.code就能获取错误的代码)
      

  2.   

    strtodatetime在sysutils中的说明:function StrToDateTime(const S: string): TDateTime;
    var
      Pos: Integer;
      Date, Time: TDateTime;
    begin
      Pos := 1;
      Time := 0;
      if not ScanDate(S, Pos, Date) or not ((Pos > Length(S)) or
        ScanTime(S, Pos, Time)) then
      begin   // Try time only
        Pos := 1;
        if not ScanTime(S, Pos, Result) or (Pos <= Length(S)) then
          ConvertErrorFmt(@SInvalidDateTime, [S]);
      end else
        if Date >= 0 then
          Result := Date + Time else
          Result := Date - Time;
    end;
    你可以直接使用scanDate, scantime检查
      

  3.   

    那个提示应该是Delphi调试过程中拦截下来的,你在Delphi的Language Exception中应该
    可以找到Stop on Delphi Exception的选项,把它去掉就可以了
      

  4.   

    利用函数StrToDate()转换自身的错误捕捉procedure TForm1.DateEditExit(Sender: TObject);
    begin
    //利用函数转换的错误捕捉来处理...
    if DateEdit1.Text<>'' then
    begin
      try
        StrToDate(DateEdit1.Text);//转换
      except
        DateEdit1.SetFocus;
        MessageBeep(0);
        raise Exception.Create('"'+DateEdit1.Text+'" 不是正确的日期格式!');
        end{try};
      DateEdit1.Text:=DateToStr(StrToDate(DateEdit1.Text));
    end{if};
    end;
      

  5.   

    ChDw的答案是对的,你脱离Delphi运行该程序就会执行到Exception里面。仔细看看Debugger的相关选项,很灵活的处理这类问题。另外,有些Exception类有ErrorCode和Message,你可以这样用:try
      //...
    except
      On ECE: EConvertError do
        ShowMessage(ECE.ClassName+': '+ECE.Message);
      On EWE: EWin32Error do
        ShowMessageFmt('%s[%d]: %s',[EWE.ClassName,EWE.ErrorCode,ECE.Message);
    end;