if (key<'0') or (key>'9') then
    begin
     key:=#0;        
     beep;
        {这儿我想让输入的东东无效,即不能输入字母,可是我的只有响铃,但还能输入}
    end;

解决方案 »

  1.   

    好象在OnKeyDown事件中吧
    keyPress只能处理标准的按键,比如数字,字母
    不能处理组合键
      

  2.   

    procedure TForm1.kshKeyPress(Sender: TObject; var Key: Char);
    begin
        if (key<'0') or (key>'9') then
        begin
            key=chr(0)
            beep{就这么简单}
        end;
    end;
     
     
      

  3.   

    procedure TForm1.kshKeyPress(Sender: TObject; var Key: Char);
    begin
        if (key<'0') or (key>'9') then
        begin
            key:=chr(0);
            beep;{就这么简单}对不起,刚才有语法错误
        end;
    end;
      

  4.   

    if not (key in ['0','1','2','3','4','5','6','7','8','9',#8]) then
      begin
        key:=#0;
        beep();
      end;
    支持baskspace键。
      

  5.   

    在OnKeyPress事件中加入:
    if not (((key >= #48) and (key <= #57)) or (key = #8)) then
        key := char(0);
      

  6.   

    在OnKeyPress事件中加入:
      if IsCharAlpha(Key) then
        Key := Chr(0);
      

  7.   

    在onkeypress事件中if isCharAlpha(key) then
       abort;要给分哦。哈...