onchange
s:=edit.text;
try
  i:=strtoint(s);
except
  .......
脱离IDE就可以用

解决方案 »

  1.   

    except
      showmessage('you can only input integer');
      

  2.   

    procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
    begin
      if not (key in ['0'..'9',#8,#13]) then
       begin
        ShowMessage('请输入数字!');
        exit;
       end;
    end;
      

  3.   

    在Edit的OnKeyPress事件里面写
      if not (Key in ['0'..'9']) then
      begin
        ShowMessage('非法数字!');
        
        // 把输入的字符删掉
      end;
      

  4.   

    if (int(Key)>57 || int(Key) <48)
    {
    Key=0;
    }