我是用edit来输入数据但是牵扯到数据类型检验问题,请教大虾怎么检验数据类型的正确性,其中包括日期类型,float,integer.

解决方案 »

  1.   

    integer:   StrToInt(Edit1.Text)
    datetime: 最好用maskedit,可以进行相应的设置,
              具体参看delphi帮助。
    float:    StrToFloat.
      

  2.   

    try 
      StrToFloat(Edit1.Text);//StrToDateTime(Edit1.Text);StrToInt(Edit1.Text);
    except
      ShowMessage('Error');
      Edit1.SetFocus;
      Exit;
    end;
      
      

  3.   

    var
      i:Extended;
    begin 
     If TryStrToFloat(Edit1.Text,i) then //如果是Float类型
     begin
      ...
     end;
    end;
      

  4.   

    VarType(const V: Variant): Integer;
    看看帮助吧:)
      

  5.   

    用一个异常处理就可以搞定:
    function IsFloat(S:String):Boolean;
    begin
      Result:=True;
      try
        StrToFloat(S);
      except
        Result:=False;
      end;
    end;
    判断 :
    if IsFloat(Edit1.Text) then
    //是Float型