比如用文本框输入数据到数据库,如何检查输入的数据类型是否匹配,delphi 里有自带函数判断数据类型么?比如判断输入是否为数字!是否是时间类型!
请教了!!

解决方案 »

  1.   

    再 KeyPress事件中 :
    if key not in ('0','1','2','3','4'等等) then key=#0
    就可以了
      

  2.   

    ——毛主席告诉我们:自己动手,丰衣足食——
    function IsIntStr(str: string): boolean;
    begin
      try
        StrToInt(str);
        result:=true;
      Except
        result:=false;
      end;
    end;function IsDateStr(str): boolean;
    begin
      TempFormat:=ShortDateFormat;  //保存操作系统的日期格式
      ShortDateFormat:='yyyy-mm-dd';//把系统日期格式改成你使用的日期格式
      try
        StrToDate(str);
        result:=true;
      except
        result:=false;
      end;
      ShortDateFormat:=TempFormat;//恢复原来的系统日期格式
    end;
      

  3.   

    办法很多,简单一点用MaskEdit
      

  4.   

    procedure TdataRelationPub.allIntOnKeypress(Sender: TObject;
      var Key: Char);
    begin
      case key of
       '0','1','2','3','4','5','6','7','8','9',#8:key:=key;
       else
       key:=#0;
       end;
    end;
    procedure TdataRelationPub.allFloatOnKeypress(Sender: TObject;
      var Key: Char);
    begin
       case key of
       '0','1','2','3','4','5','6','7','8','9',#8:key:=key;
       '.':begin
           if pos('.',TCustomEdit(Sender).Text)<>0 then
           key:=#0;
           end
       else
       key:=#0;
       end;
    end;
      

  5.   

    if Assigned(CurField)  then
       begin
        if (CurField.DataType in [ftFloat,ftCurrency,ftBCD]) then
          begin
          if not((key in ['0'..'9','.','-',#8])) then
           begin
            key := #0
           end
          else
            begin
              if (Key='.') and (Pos('.',TEdit(Sender).Text)<>0) then
                 Key:=#0
              else if
                 (Key='-') and (Pos('-',TEdit(Sender).Text)<>0) then
                 Key:=#0;
            end;
          end
        else if (CurField.DataType in [ftAutoInc,ftSmallint, ftInteger, ftWord,
                     ftBytes,ftLargeint]) then
           begin
           if not ((Key in ['0'..'9','-',#8])) then
            begin
             Key:=#0
            end
            else
            begin
              if(Key='-') and (Pos('-',TEdit(Sender).Text)<>0) then
                 Key:=#0;
            end;
           end
        else
           Exit;
       end;CurField是字段类型。
      

  6.   

    procedure TQueryBilForm.ComPTextKeyPress(Sender: TObject; var Key: Char);
    里面写!
      

  7.   

    用Format系列函数格式化文本框的内容,再判断