在ONKEYPRESS事件下写代码
if Key not in ['0'..'9'] then 
  Key :=#0;

解决方案 »

  1.   

    if (key not in [0..9]) then
      

  2.   

    在KeyPress里面输入如下代码:
    //#8是退格符
    if not (Key in [#8, '0'..'9']) then 
    begin
      //不是合法字符        
      //吃掉这个字符
      Key := #0;
    end;  
      

  3.   

    onkeypress   if (key >='0')and(key <= '9' )or (key=chr(8))or(key=chr(46))  then
           exit
         else
             key := chr(0);
      

  4.   

    在KeyPress里面输入如下代码:
    if (key>#47 or key<#58) or (key=#8) then
    begin
      key:=#0;
    end;
      

  5.   

    在ONKEYPRESS事件下写代码
      if ((key>#57) or (key<#48)) and (key<>#8) then
      begin
        key:=#0;
      end;
      

  6.   

    在ONKEYPRESS事件下写代码
      if ((key>#57) or (key<#48)) and (key<>#8) then
      begin
        key:=#0;
      end;
    绝对好用!!
      

  7.   

    //下面是我作的项目里面的一段程序,也是对输入到TEdit的字符进行限制的
    //在KeyPress事件中加入一条判断语句就可以了
    procedure TdlgNewStockDetail.edtGiveupUnitKeyPress( Sender: TObject;
      var Key: Char);
    begin
      inherited;//这行你可以不用.
      if ( Ord( Key) >= 32) and ( ( Key < '0') or ( Key > '9')) then
        Key := #0;
    end;
      

  8.   

    干吗那么麻烦, 用maskedit不就完了?