本人刚学delphi,在一个文本框中,我要判断用户输入的是否为数字串,如果不是数字(含有字母或其他字符)我要给提示:让用户输入数字串.该怎么判断,有这样的函数吗?请指示.谢谢!

解决方案 »

  1.   

    在onkeypress事件里写;
    if not (key in ['0'..'9'])then
    begin
      showmessage('请输入数字');
      key:=chr(0);
    end;
      

  2.   

    procedure Tform1.edit1KeyPress(Sender: TObject;
      var Key: Char);
    begin
       If ((key < '0') Or ( key > '9')) and (key <> chr(8))  then
        key := #0;
    end;
      

  3.   

    同意:
    在onkeypress事件里写;
    if not (key in ['0'..'9'])then
    begin
      showmessage('请输入数字');
      key:=chr(0);
    end;
      

  4.   

    先谢谢了,输入小数点也可以,小数点或句号的ascll码值是多少啊?
      

  5.   

    if not (key in ['0'..'9','.'])then 这个是可以输入小数点的
    begin
      showmessage('请输入数字');
      key:=chr(0);
    end;