如何控制在edit中只输入数字?
另外我怎么知道一些字符的Key值,如回车键key=13,那么退格键等其它的呢?

解决方案 »

  1.   

    if key not in [0..9] then key:=#0;
      

  2.   

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

  3.   

    在KeyDown事件里通过对Key参数的控制来实现
    procedure DoKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
      

  4.   

    if not (key in ['0'..'9'],#8) then
    begin
      key:=#0;
      messagebeep(1);
    end;
    #8是退格键,应该让它也起作用
    2.很简单
    在edit的onkeydown中写
    showmessage(inttostr(key))
      

  5.   

    在OnKeyPress中
     
      if key not in [0..9] then key:=#0;在知道Key值,查ASCII 码表,或在Delphi帮助的索引中 敲 Virtual key codes
     
     
      

  6.   

    //只允许输入数字
      if not (Key in ['0'..'9',#13,#8,#46]) then//不应该把回车和DEL、BACKSPACE过滤掉
      begin
        key := #0;
      end;