try
  strtoint('字符串') ;
except
  Result := '不是数字字串' ; 
end ;或者通过读取每个字符进行判段也行

解决方案 »

  1.   

    我刚写的一个函数,传入字符串,判断TURE/FALSE即可。
     //判断字符串是不是数值 
      function IsNumber(s: string): boolean;
      var
        i, iLength: integer;
      begin
        iLength := Length(s);
        for i := 1 to iLength do
        begin
         if not (s[i] in ['0'..'9']) then
          begin
            Result := false;
            exit;
          end
        end;
        Result := true;
      end;
    结帖吧。
      

  2.   

    没有现成的函数,自己写一个,思路与liujc(阿聪)的相同。
    function ValidateInt(IntString:String):Boolean;
    begin
      try
        StrToInt(IntString);
        result:=True;
      except 
        result:=False;
      end;
    end;
      

  3.   

    赞成dainy(方程式)的方式,尽量少用try ... except ... end的形式作普通处理,因为这样很号资源的。
      

  4.   

    //一个重复的问题不知道要赚多少分
    //from
    http://kingron.myetang.com/zsfunc06.htm(*//
    标题:检查数字字符串
    说明:使用于运用程序检查用户数字输入
    设计:Zswang
    日期:2002-01-24
    支持:[email protected]
    //*)///////Begin Source
    function IsNumber(mStr: string): Boolean; { 返回字符串是否是正确的数字表达 }
    var
      I: Real;
      E: Integer;
    begin
      Val(mStr, I, E);
      Result := E = 0;
      E := Trunc(I);
    end; { IsNumber }function IsInteger(mStr: string): Boolean; { 返回字符串是否是正确的整数表达 }
    var
      I: Integer;
      E: Integer;
    begin
      Val(mStr, I, E);
      Result := E = 0;
      E := Trunc(I);
    end; { IsInteger }
    ///////End Source///////Begin Demo
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      CheckBox1.Checked := IsNumber(Edit1.Text);
      CheckBox2.Checked := IsInteger(Edit1.Text);
    end;
    ///////End Demo
      

  5.   

    同意dainy的方法
    如果再加工一下,还可以判断是否是二进制、16进制的数值!
      

  6.   

    Val(S; var V; var Code: Integer);Val converts the string value S to its numeric representation, as if it were read from a text file with Read.S is a string-type expression; it must be a sequence of characters that form a signed real number. V is an integer-type or real-type variable. If V is an integer-type variable, S must form a whole number. Code is a variable of type Integer.If the string is invalid, the index of the offending character is stored in Code; otherwise, Code is set to zero. For a null-terminated string, the error position returned in Code is one larger than the actual zero-based index of the character in error.example:var
      i:Double;
      Code:Integer;
    begin
      Val(Instr,i,Code);
      if Code = 0  then 返回 i
      else 返回ERROR
    end;
      

  7.   

    这个是正确的!
     //判断字符串是不是数值 
      function IsNumber(s: string): boolean;
      var
        i, iLength: integer;
      begin
        iLength := Length(s);
        for i := 1 to iLength do
        begin
         if not (s[i] in ['0'..'9']) then
          begin
            Result := false;
            exit;
          end
        end;
        Result := true;
      end;