在DELPHI中如何判断该字段值为数值型还是字符型。

解决方案 »

  1.   

    {$HINTS OFF}
    function IsNumeric(AStr: string): Boolean;
    var
      Value: Double;
      Code: Integer;
    begin
      Val(AStr, Value, Code);
      result := Code = 0;
    end;
    {$HINTS ON}
      

  2.   

    delphi中用variant来存放字段值
    用varisnumric()可以判断变体的是不是数字。
      

  3.   

    uses
     Variants;function VarIsNumeric(const V: Variant): Boolean;
    -----------------------------------------------------------
    DescriptionVarIsNumeric returns True if the given variant抯 type code indicates a numeric value of some sort. This can be either a floating-point value or an ordinal value. If the variant contains any other type of value, the function result is False.
      

  4.   

    for I := 0 to DataSet.Fields.Count - 1 do
        case DataSet.Fields[I].DataType of
          ftSmallint, ftInteger, ftWord, ftFloat, ftCurrency, ftBCD:
          showmessage('数字型');
        ftString:
          showmessage('字符型');
        end;