function StrIsDate(S:String):Boolean;
begin
  Result:=True;
  try
    StrToDate(s);
  except
    Result:=False;
  end;
end;

解决方案 »

  1.   

    function StrIsDate(S:String):Boolean;
    begin
      Result:=True;
      try
        StrToDate(s);
      except
        Result:=False;
      end;
    end;上面这个行的,当s是非法的字符就可以了。if StrIsDate('2002-kk-sfsdf')=false then
    begin
        showmessage('日期输入错误!!');
        exit;
    end;
      

  2.   

    Delphi6有 IsDateTime函数Declaration
    function IsDateTime : Boolean;
    Description
    Each Chart Axis can consider values to be normal numbers or DateTime values. This function returns if the Axis dependent values are DateTime or not.
      

  3.   

    function StrIsDate(S:String):Boolean;
    begin
      Result:=True;
      try
        StrToDate(s);
      except
        Result:=False;
      end;
    end;
    同意楼上
      

  4.   

    但它为什么弹出的是系统的出错对话框,我用的是delphi5.0
      

  5.   

    楼上们都不错,你调试在DEBUG下,DELPHI还是会抛出异常的,你单独编译运行就没问题了。
      

  6.   

    函数如下:
         function isdate(s:string):boolean;
         begin
           result:=false;
           try
             strtodate(s);
             result:=true;
           except
             on econverterror do
               result:=false;
             end;
         end;
      

  7.   

    try
    begin
      strtodate(str);
    except
    finally
    如果出异常的话那就不是正确的日期格式。
      

  8.   

    不要点 run执行,
    按ctrl+F9 编译,然后在工程目录找到
    那个.exe程序,这样运行。。
      

  9.   

    还是不行,返回不了,一运行就中断,只有手动program reset?
      

  10.   

    判断一个字符串变量是“某种类型”,最通用的方法是在try except结构中对该字符串进行相应的转换,有异常就说明该字符串不是“该类型”的
      

  11.   

    TryStrToDate();
    TryStrToDateTime();
    TryStrToTime();
      

  12.   

    不要在 delphi环境中运行。~!
      

  13.   

    第一个回答的兄弟方法正确
    你说不到扑获,可能你是在便宜环节中运行的吧你到外边直接运行.exe就可以了
    可以扑获的