直接放一个TUpDown控件,Associate指向该Edit即可

解决方案 »

  1.   

    Val()
    //or
    TryStrToInt()
      

  2.   

    try
       strtoint^
    except
       出错提示
    end;
    反正你要将edit中的字符串转化为数字的吗!
      

  3.   

    procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
    begin
      if not (Key in ['0'..'9']) then
      begin
        Key := #0;
        ShowMessage('非法数字!');
      end;
    end;
      

  4.   

    var
      I: Integer;
      E: Integer;
    begin
      Val(Edit1.Text, I, E);
      if E <> 0 then
        ShowMessage('以前的帖子问得太多了');
    end;
      

  5.   

    procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
    begin
      if (Ord(Key) <47) or (Ord(Key) > 58) then
        Key := #0;
    end;
      

  6.   

    以下这种做法,对于用户使用ctrl+C、V拷进来的数据就不能判断了procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
    begin
      if (Ord(Key) <47) or (Ord(Key) > 58) then
        Key := #0;
    end;
      

  7.   

    try 
    strtoint(edit1.text)
    except
    showmessage('请输入整数');
    end;
      

  8.   

    在onchange事件中,用try..except来判断正确性。
      

  9.   

    我刚写的一个函数,传入字符串,判断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;
      

  10.   

    可以放在 onexit(失去焦点?) 事件中检测!
      

  11.   

    我给你一段源码,保证明没问题!
    在onKeyPess事件中加入一下代码
    if (Key < '0') or (Key > '9') 
        then Key := Chr(0);