try
  StrToDate('2002-05-41');
  Result := True;
except
  Result := False;
end;

解决方案 »

  1.   

    在定义一个数组,用来放结果调用
    try
      StrToDate('2002-05-41');
      Result := True;
    except
      Result := False;
    end;
      

  2.   

    对啊,chechy(我爱洁洁)的方法就对了
      

  3.   

    TryStrToDate() //for Delphi6
    //大家怎么不用?
      

  4.   

    同意 zswang(伴水) 的方法:function TryStrToDate(const S: string; out Value: TDateTime): Boolean;这是DELPHI6自带的函数
      

  5.   

    同意 zswang(伴水) 的方法:function TryStrToDate(const S: string; out Value: TDateTime): Boolean;这是DELPHI6自带的函数。
    类似的还有:
    function TryStrToDateTime(const S: string; out Value: TDateTime): Boolean;
    function TryStrToInt(const S: string; out Value: Integer): Boolean;
    function TryStrToInt64(const S: string; out Value: Int64): Boolean;
    function StrToFloat(const S: string): Extended;
    function StrToBool(const S: string): Boolean;
    等等。
      

  6.   

    To  zswang(伴水)(* 嘻 *) ,你不说,我怎么知道。
      

  7.   

    vjun :TryStrtoDate 里的out 是代表什么?我这里也是delpih 6
    用不了
      

  8.   

    我用了vjun,zswang(伴水)了,谢谢各位!
      

  9.   

    var
      ThisDate: TDateTime;
    begin
      if TryStrToDate('2001-12-31', ThisDate) then
        ShowMessage('正确的日期格式:' + DateToStr(thisdate));  if TryStrToDate('2001-12-32', ThisDate) then
        ShowMessage('错误的日期格式');
    end;
      

  10.   

    写错了,更正如下:
    var
      ThisDate: TDateTime;
    begin
      if TryStrToDate('2001-12-31', ThisDate) then
        ShowMessage('正确的日期格式:' + DateToStr(thisdate));  if not TryStrToDate('2001-12-32', ThisDate) then
        ShowMessage('错误的日期格式');
    end;
      

  11.   

    如果这是个任意字符能判断吗?比如“可靠棵'
    trystrtodate(“可靠棵',thisdate)
    好象不行 了
      

  12.   

    这是我搞编程,也是搞DELPHI,组长让我做的一个身份证升位程序,半年以前做的,里面有关于日期校验的咚咚,也许可以帮你!要声明的是,这是我写的第一个DELPHI程序,用的DELPHI5,而且对编程没有任何经验,只是在上学时学了TC,FORTRAN,所以里面的很多咚咚,其实一个函数就可以搞定,但是那是没有人指导我,自己瞎琢磨搞的,大家别笑话啊unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls;type
      TForm1 = class(TForm)
        Label1: TLabel;
        Label2: TLabel;
        Edit1: TEdit;
        Edit2: TEdit;
        Button1: TButton;
        Button2: TButton;
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.DFM}//乘方函数,输入底数和幂,返回整型值
    Function ChF(Di:Integer;Mi:Integer):integer;
      var
        i:Integer;
        RS:Integer;  begin
        RS:=1;
        for I:=1 to Mi do
          RS:=RS*Di;
        result:=RS;
      end;
    //出生日期校验函数
    Function CheckDate(S:String):String;
    var
      YearTmp:Integer;
      Montmp:Integer;
      StrTmp:string;
      DateTmp:Integer;
    begin
      YearTmp:=(Integer(s[7])-48)*1000+(Integer(s[8])-48)*100+
          (Integer(s[9])-48)*10+(Integer(s[10])-48);
      MonTmp:=(Integer(s[11])-48)*10+(Integer(s[12])-48);
      DateTmp:=(Integer(s[13])-48)*10+(Integer(s[14])-48);
      if (MonTmp=1)or(MonTmp=3)or(MonTmp=5)or(MonTmp=7)or(MonTmp=8)or(MonTmp=
          10)or(MonTmp=12)then
        begin
          if (DateTmp>31)or(DateTmp=0) then
            StrTmp:='no'
          else
            StrTmp:='yes';
        end  else if(MonTmp=4)or(MonTmp=6)or(MonTmp=9)or(MonTmp=11)then
        begin
          if(DateTmp>30)or(DateTmp=0)then
            StrTmp:='no'
          else
            StrTmp:='yes';
        end  else if(MonTmp>12)or(MonTmp=0)then
        StrTmp:='no'
      else if MonTmp=2 then
        begin
          if(yearTmp mod 4<>0)and(MonTmp=2)and(DateTmp>28)then
            StrTmp:='no'
          else if (YearTmp mod 4=0)and(MonTmp=2)and(DateTmp>29)then
            StrTmp:='no'
          else
            StrTmp:='yes';
        end
      else
        StrTmp:='no';  result:=StrTmp;end;procedure TForm1.Button1Click(Sender: TObject);
      var
        I:integer;
        StrGet:String;
        Strtmp:String;
        IntTmp:integer;
        LastStr:String;begin
      StrGet:=edit1.Text;
      StrTmp:='';
      IntTmp:=0;
      //判断输入是否为空
      if StrGet='' then
        begin
          MessageDlg('搞什么嘛!没有输入身份证号码~!', mtError,
          [mbOk], 0);
          exit;
        end
      //进行位数判断
      else if (Length(StrGet)<>15)and(length(StrGet)<>17)and
        (length(StrGet)<>18) then
        begin
          MessageDlg('我靠!位数不对,应该是15、17或者18位~!',
          mtError,[mbOk], 0);
          exit;
        end
      //如果输入为15位,加入“19”
      else if length(StrGet)=15 then
        begin
          for i:=1 to 6 do
            StrTmp:=StrTmp+StrGet[i];
          StrTmp:=StrTmp+'19';
          for I:=7 to Length(StrGet) do
            StrTmp:=StrTmp+StrGet[i];
        end
      //如果输入为17位
      else if length(StrGet)=17 then
        StrTmp:=StrGet
      //如果输入为18位
      else if Length(StrGet)=18 then
        begin
          for i:=1 to 17 do
            StrTmp:=StrTmp+StrGet[i];
        end;  for I:=17 downto 1 do
        begin
          //判断输入是否含有非数字字符
          if(Integer(StrTmp[i])<48)or (Integer(Strtmp[i])>57) then
            begin
              messagedlg('老大!到底你会不会敲键盘啊!录入有非数字字符~!',mtError,[mbOk],0);
              StrTmp:='';
              exit;
            end
        end;
      //校验日期
      if CheckDate(StrTmp)='no' then
        begin
          messagedlg('黑老子,哪里有这种出生日期呀~!',mtError,[mbOk],0);
          StrTmp:='';
          exit;
        end
      else
        begin
          for i:=17 downto 1 do
            begin
              IntTmp:=IntTmp+(ChF(2,i)mod 11)*(integer(StrTmp[18-i])-48);
            end;
          IntTmp:=IntTmp mod 11;
           case IntTmp of
                0:LastStr:='1';
                1:LastStr:='0';
                2:LastStr:='X';
                3:LastStr:='9';
                4:LastStr:='8';
                5:LastStr:='7';
                6:LastStr:='6';
                7:LastStr:='5';
                8:LastStr:='4';
                9:LastStr:='3';
                10:LastStr:='2';
           end;
        end;
        if StrTmp='' then
          edit2.Text:=''
        else
          Edit2.Text:=StrTmp+LastStr;
    end;procedure TForm1.Button2Click(Sender: TObject);
    begin
      Close;
    end;end.