帮助文件里面有一个isdatetime函数,但好象不适用

解决方案 »

  1.   

    那自己写几句
    try
      StrToDateTime(edit1.text);
    except
      Showmessage('不是日期');
      ..其它处理..
    end;
    可以写在edit的onExit事件或其它地方
      

  2.   

    先将edittext转换为日期类型,如不成功说明不是日期类型
      

  3.   

    D6以上可以
    if TryStrToDateTime(edit1.text, nDate) then
      showmessage("是日期");uses
      dateUtils;
      

  4.   

    TryStrToDateTime(edit1.text, nDate) ? 没有这个函数吧
      

  5.   

    用try except结构是不行的,刚试过
      

  6.   

    我写的一个函数,请参考:
    function CheckDateTimeValid(aString: string): boolean;
    begin
      aString := Copy(aString,1,16);
      if aString = '' then
        begin
          result := true;
          exit;
        end;
      if (trim(aString) = '/  /     :')  or
         (trim(aString) = '-  -     :')  then
        begin
          result := true;
          exit;
        end;
      if (Length(aString) <> 16) or
         ((Pos(' ',aString) <> 0) and (Pos(' ',aString) <> 11)) then
      begin
        Result := false;
        InformationMessageBox('无效');
        exit;
      end;
      try
        strtodatetime(aString);
        result := true;
      except
        InformationMessageBox('无效');
        result := false;
      end;
    end;
      

  7.   

    try except 在编译的时候不管用,但在exe文件中起作用了,刚才是我弄错了,谢谢大家的帮助,也谢谢 jinjintalk(西门吹雪)。
      

  8.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, DateUtils, StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        Edit1: TEdit;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    var
      nDate: TDateTime;
    begin
      if TryStrToDateTime(Edit1.Text, nDate) then
        ShowMessage('IS DateTime');
    end;end.
      

  9.   

    记得
    uses
      dateUtils;
      

  10.   

    trystrtodatetime 也可以,谢谢你 g961681(技术庸人(新的开始|新的挑战))
      

  11.   

    TryStrToDateTime(edit1.text, nDate)====CSDN 小助手 V2.0 2005年10月16日发布====
    CSDN小助手是一款脱离浏览器也可以访问Csdn论坛的软件
    界面:http://blog.csdn.net/Qqwwee_Com/archive/2005/10/16/504620.aspx
    下载:http://szlawbook.com/csdnv2/csdnv2.rar为神六喝彩,向所有科技工作者致敬!
    拒绝日货。
      

  12.   


    procedure TForm2.RzEdit10KeyPress(Sender: TObject; var Key: Char);
    begin
    if (not (key in ['0'..'9',#8])) and (key <>':') and (key<>'-') and (key<>' ')then key:=#0;
    end;procedure TForm2.RzEdit10Enter(Sender: TObject);
    begin
    if RzBitBtn4.Tag=0 then MessageBox(Handle,'&Ograve;&ordf;&Ocirc;&ouml;&frac14;&Oacute;&ETH;&Aring;&Iuml;&cent;&Ccedil;&euml;&Iuml;&Egrave;&sup2;é&Ntilde;&macr;&ordm;ó&Ocirc;&Ugrave;&micro;&atilde;&raquo;÷&Ocirc;&ouml;&frac14;&Oacute;°&acute;&Aring;&yen;&Ocirc;&ouml;&frac14;&Oacute;&ETH;&Aring;&Iuml;&cent;','&Igrave;á&Ecirc;&frac34;&ETH;&Aring;&Iuml;&cent;',MB_OK+MB_ICONINFORMATION)
      else TRzEdit(Sender).Text:=FormatDateTime('yyyy-mm-dd hh:mm:ss',Now);
    end;procedure TForm2.RzEdit10Exit(Sender: TObject);
    var
      i,temnum:Integer;
      str,substr:string;
    begin
      if RzBitBtn4.Tag<>0 then
      begin
      str:=RzEdit10.Text;
      if length(str)=19 then
      begin
      for i:=1 to length(str) do
      begin
        case i of
          1..4,6..7,9..10,12..13,15..16,18..19:
            if (str[i]<'0') or (str[i]>'9') then
            begin
              MessageBox(Handle,'&Auml;ú&Ecirc;&auml;&Egrave;&euml;&micro;&Auml;&Egrave;&Otilde;&AElig;&Uacute;&Ecirc;±&frac14;&auml;&cedil;&ntilde;&Ecirc;&frac12;&sup2;&raquo;&Otilde;&yacute;&Egrave;·,&Ccedil;&euml;&Ouml;&Oslash;&ETH;&Acirc;&Ecirc;&auml;&Egrave;&euml;(&Agrave;&yacute;&Egrave;&ccedil;:2005-10-10 10:10:10)','&Igrave;á&Ecirc;&frac34;&ETH;&Aring;&Iuml;&cent;',MB_OK+MB_ICONINFORMATION);
              RzEdit10.SetFocus;RzEdit10.SelectAll;
              Exit;
            end;
          5,8:
            if str[i]<>'-' then
            begin
              MessageBox(Handle,'&Auml;ú&Ecirc;&auml;&Egrave;&euml;&micro;&Auml;&Egrave;&Otilde;&AElig;&Uacute;&Ecirc;±&frac14;&auml;&cedil;&ntilde;&Ecirc;&frac12;&sup2;&raquo;&Otilde;&yacute;&Egrave;·,&Ccedil;&euml;&Ouml;&Oslash;&ETH;&Acirc;&Ecirc;&auml;&Egrave;&euml;(&Agrave;&yacute;&Egrave;&ccedil;:2005-10-10 10:10:10)','&Igrave;á&Ecirc;&frac34;&ETH;&Aring;&Iuml;&cent;',MB_OK+MB_ICONINFORMATION);
              RzEdit10.SetFocus;RzEdit10.SelectAll;
              Exit;
            end;
          11:
            if str[i]<>' ' then
            begin
              MessageBox(Handle,'&Auml;ú&Ecirc;&auml;&Egrave;&euml;&micro;&Auml;&Egrave;&Otilde;&AElig;&Uacute;&Ecirc;±&frac14;&auml;&cedil;&ntilde;&Ecirc;&frac12;&sup2;&raquo;&Otilde;&yacute;&Egrave;·,&Ccedil;&euml;&Ouml;&Oslash;&ETH;&Acirc;&Ecirc;&auml;&Egrave;&euml;(&Agrave;&yacute;&Egrave;&ccedil;:2005-10-10 10:10:10)','&Igrave;á&Ecirc;&frac34;&ETH;&Aring;&Iuml;&cent;',MB_OK+MB_ICONINFORMATION);
              RzEdit10.SetFocus;RzEdit10.SelectAll;
              Exit;
            end;
          14,17:
            if str[i]<>':' then
            begin
              MessageBox(Handle,'&Auml;ú&Ecirc;&auml;&Egrave;&euml;&micro;&Auml;&Egrave;&Otilde;&AElig;&Uacute;&Ecirc;±&frac14;&auml;&cedil;&ntilde;&Ecirc;&frac12;&sup2;&raquo;&Otilde;&yacute;&Egrave;·,&Ccedil;&euml;&Ouml;&Oslash;&ETH;&Acirc;&Ecirc;&auml;&Egrave;&euml;(&Agrave;&yacute;&Egrave;&ccedil;:2005-10-10 10:10:10)','&Igrave;á&Ecirc;&frac34;&ETH;&Aring;&Iuml;&cent;',MB_OK+MB_ICONINFORMATION);
              RzEdit10.SetFocus;RzEdit10.SelectAll;
              Exit;
            end;
          end;
          end;  substr:=Copy(str,6,2);
      temnum:=StrToInt(substr);
      if (temnum<1) or (temnum>12) then
      begin
        MessageBox(Handle,'&Auml;ú&Ecirc;&auml;&Egrave;&euml;&micro;&Auml;&Ocirc;&Acirc;·&Yacute;&cedil;&ntilde;&Ecirc;&frac12;&sup2;&raquo;&Otilde;&yacute;&Egrave;·,&Ccedil;&euml;&Ouml;&Oslash;&ETH;&Acirc;&Ecirc;&auml;&Egrave;&euml;(&Agrave;&yacute;&Egrave;&ccedil;&Ocirc;&Acirc;·&Yacute;·&para;&Icirc;§:01-12)','&Igrave;á&Ecirc;&frac34;&ETH;&Aring;&Iuml;&cent;',MB_OK+MB_ICONINFORMATION);
        RzEdit10.SetFocus;RzEdit10.SelectAll;
        Exit;
      end;  substr:=Copy(str,9,2);
      temnum:=StrToInt(substr);
      if (temnum<1) or (temnum>31) then
      begin
        MessageBox(Handle,'&Auml;ú&Ecirc;&auml;&Egrave;&euml;&micro;&Auml;&Egrave;&Otilde;&cedil;&ntilde;&Ecirc;&frac12;&sup2;&raquo;&Otilde;&yacute;&Egrave;·,&Ccedil;&euml;&Ouml;&Oslash;&ETH;&Acirc;&Ecirc;&auml;&Egrave;&euml;(&Agrave;&yacute;&Egrave;&ccedil;&Egrave;&Otilde;·&para;&Icirc;§:01-31)','&Igrave;á&Ecirc;&frac34;&ETH;&Aring;&Iuml;&cent;',MB_OK+MB_ICONINFORMATION);
        RzEdit10.SetFocus;RzEdit10.SelectAll;
        Exit;
      end;  substr:=Copy(str,12,2);
      temnum:=StrToInt(substr);
      if temnum>23 then
      begin
        MessageBox(Handle,'&Auml;ú&Ecirc;&auml;&Egrave;&euml;&micro;&Auml;&ETH;&iexcl;&Ecirc;±&cedil;&ntilde;&Ecirc;&frac12;&sup2;&raquo;&Otilde;&yacute;&Egrave;·,&Ccedil;&euml;&Ouml;&Oslash;&ETH;&Acirc;&Ecirc;&auml;&Egrave;&euml;(&Agrave;&yacute;&Egrave;&ccedil;&ETH;&iexcl;&Ecirc;±·&para;&Icirc;§:00-23)','&Igrave;á&Ecirc;&frac34;&ETH;&Aring;&Iuml;&cent;',MB_OK+MB_ICONINFORMATION);
        RzEdit10.SetFocus;RzEdit10.SelectAll;
        Exit;
      end;  substr:=Copy(str,15,2);
      temnum:=StrToInt(substr);
      if temnum>59 then
      begin
        MessageBox(Handle,'&Auml;ú&Ecirc;&auml;&Egrave;&euml;&micro;&Auml;·&Ouml;&Ouml;&Oacute;&cedil;&ntilde;&Ecirc;&frac12;&sup2;&raquo;&Otilde;&yacute;&Egrave;·,&Ccedil;&euml;&Ouml;&Oslash;&ETH;&Acirc;&Ecirc;&auml;&Egrave;&euml;(&Agrave;&yacute;&Egrave;&ccedil;·&Ouml;&Ouml;&Oacute;·&para;&Icirc;§:00-59)','&Igrave;á&Ecirc;&frac34;&ETH;&Aring;&Iuml;&cent;',MB_OK+MB_ICONINFORMATION);
        RzEdit10.SetFocus;RzEdit10.SelectAll;
        Exit;
      end;  substr:=Copy(str,18,2);
      temnum:=StrToInt(substr);
      if temnum>59 then
      begin
        MessageBox(Handle,'&Auml;ú&Ecirc;&auml;&Egrave;&euml;&micro;&Auml;&Atilde;&euml;&cedil;&ntilde;&Ecirc;&frac12;&sup2;&raquo;&Otilde;&yacute;&Egrave;·,&Ccedil;&euml;&Ouml;&Oslash;&ETH;&Acirc;&Ecirc;&auml;&Egrave;&euml;(&Agrave;&yacute;&Egrave;&ccedil;&Atilde;&euml;·&para;&Icirc;§:00-59)','&Igrave;á&Ecirc;&frac34;&ETH;&Aring;&Iuml;&cent;',MB_OK+MB_ICONINFORMATION);
        RzEdit10.SetFocus;RzEdit10.SelectAll;
        Exit;
      end;
      end else
      begin
        MessageBox(Handle,'&Ccedil;&euml;&Ecirc;&auml;&Egrave;&euml;&Iacute;ê&Otilde;&ucirc;&micro;&Auml;&Egrave;&Otilde;&AElig;&Uacute;&Ecirc;±&frac14;&auml;&ETH;&Aring;&Iuml;&cent;','&Igrave;á&Ecirc;&frac34;&ETH;&Aring;&Iuml;&cent;',MB_OK+MB_ICONINFORMATION);
        RzEdit10.SetFocus;RzEdit10.SelectAll;
        Exit;
      end;
      end;
    这是我在开发软件一部分代码:大致给你说下思路:
     1、KEYPRESS事件,可以输入的值
     2、ENTER   取系统事件,也可以修改
     3、EXIT   判断