如题

解决方案 »

  1.   

    在OnChange事件中处理:
    procedure TForm.EditChange(Sender: TObject);
    begin
      try
        StrToInt((Sender as TEdit).Text);
      except
        (Sender as TEdit).Text:=Copy((Sender as TEdit).Text,1,
          Length((Sender as TEdit).Text)-1);
        (Sender as TEdit).SelStart:=Length((Sender as TEdit).Text);
      end;
    end;
      

  2.   

    在 Edit 的 KeyPress 事件中加入下列代码: 
      if not((key in ['0'..'9',#8]) ) then 
        key := #0; 
      

  3.   

    procedure TformMain.edtPortKeyPress(Sender: TObject; var Key: Char);    //限制edtPort的输入只能是数字
    begin
      if not (key in ['0'..'9', #8]) then
        Key:= #0;
    end;
      

  4.   

    KeyPress不完善
    如果像紫光或微软拼音那样一下输入一串就不行了
    还有么输入多个小数点也很难控制
    再有就是Ctrl+C,Ctrl+V...
      

  5.   

    这个问题讨论过好多次了,
    我觉得还是OnChange事件处理最完善。
    就是调试的时候报错烦一点,执行.exe就没问题了。
      

  6.   

    在 Edit 的 KeyPress 事件中加入下列代码: 
      if not((key in ['0'..'9',#8]) ) then 
        key := #0; 
    在KeyPress 事件处理最好,该事件是专门处理输入的。
      

  7.   


      if not((key in ['0'..'9',#8]) ) then 
        key := #0;
      

  8.   

    谢谢大家的关注,马上发分。TO FrameSniper(框架狙击手) 
      呵呵,#8不是空格,是回退键。