我做了一个判断日期的函数
//判断字符串是否是有效日期类型
function isdate(s:string):boolean;
begin
 result:=false;
try
  strtodate(s);
  result:=true;
except
  on econverterror do
  result:=false;
end;
end;procedure TForm2.Button1Click(Sender: TObject);
begin
if isdate(trim(edit1.Text)) = false then
  begin
    MessageDlg('日期输入不正确!', mtWarning, [mbOK], 0);
    exit;
  end;
end;
当调用返回时总是先弹出系统提示的错误:project project2.exe raised exception class econverterror with message "edit1'is not a valid date'.
process stopped.use step or run to contiue.
点击ok按钮后才弹出MessageDlg('日期输入不正确!', mtWarning, [mbOK], 0);
为什么不直接弹出这个提示?郁闷!!。

解决方案 »

  1.   

    你的另一贴:
    http://community.csdn.net/Expert/topic/5246/5246644.xml?temp=.3406488
      

  2.   

    正常啊,当你在IDE的调试环境运行时会在except 捕获之前Delphi给你个提示不在开发环境中运行不会有这个提示滴直接跑.exe试试看吧。。
      

  3.   

    这样比较通用,运行效果以直接运行exe为准
    function isdate(s:string):boolean;
    begin
     result:=false;
    try
    ///////
      VarToDateTime(s);
      result:=true;
    except
      on econverterror do
      result:=false;
    end;
    end;
      

  4.   

    试试我吧var
      TmpDate: TDateTime;
    begin
    方法一:
      TmpDate:= StrToDateDef( Edit1.Text, 0 );
    方法二:
      TmpDate:= 0;
      if TryStrToDate( Edit1.Text, TmpDate ) thenend;