如何实现让一个Edit只允许输入数字?
另外,,如何实现让一个Edit只允许输入字符?这两个功能分别如何实现,请高手指点!谢谢!

解决方案 »

  1.   

    我当然知道在 onkeyup事件中写了!
      

  2.   

    OnKeyPressif Ord(Key) = VK_BACK then
        Exit;
    if not (Key in ['0'..'9']) then
      Key := #0;
      

  3.   

    OnKeyPress:procedure AllowCharKeyIn(var Key: char);
    var
      bt: Integer;
    begin
      bt := Ord(Key);
      if bt = VK_BACK then
        Exit;
      if (bt < Ord('A'))
        or (bt > Ord('z'))
        or ((bt > Ord('Z')) and (bt < Ord('a'))) then
        Key := #0;
    end;
      

  4.   

    procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
    begin
     if not (Key in ['0'..'9','.',#8])then key:=#0 ;
    end;
      

  5.   

    在onkeypress事件中判断
    if not (key in ['0','1',...]) then
      

  6.   

    procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
       begin 
       if not(key in['0'..'9',#8])then 
        begin 
         key:=#0; 
         MessageBeep(1); 
        end; 
       end;
      

  7.   

    procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
    begin
     if not (Key in ['0'..'9','.',#8]) then 
       begin
         beep;
         key:=#0 ;
       end;
    end;
      

  8.   

    procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char); begin if (Key < '0') or (Key > '9') then Key := Chr(0); end; 
      

  9.   

    呵呵, 应该先搜一下, 在问, 这样的问题在csdn上老多了, 呵呵, 可惜了分了!
      

  10.   

    照hjf1223(阿不) 说的做就可以了,很精练
      

  11.   

    with Edit1 do
      SetWindowLong(Handle,
         GWL_STYLE,
         GetWindowLong(Handle, GWL_STYLE) or ES_NUMBER);
      

  12.   

    只允许输入数字
    procedure Tform1.edit1KeyPress(Sender:TObject;var Key:Char);
    var
      m:Boolean;
    begin
    m:=(key<#8)or(key>#8)and(key<#45)or(key>#46)and(key<#48)or(key>#57);
    if m then
    key:=#0;
    end;
      

  13.   

    只允许输入字符
    procedure TForm1.Edit2KeyPress(Sender: TObject; var Key: Char);
    var a : boolean;
    begin
    a:=(key<#8)or(key>#8)and(key<#65)or(key>#65)and((key>#90)and(key<#97))or (key>#122);
    if a then
    key :=#0;
    end;
      

  14.   

    请问:whythinkwhy(一品皇山) 
    只能输入中文字,则如何处理呢?
      

  15.   

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

  16.   

    if key not in ['0'..'9',#8] then abort
      

  17.   

    晕,写一个函数
    FUNCTION IsInt(value:string):boolean;
    begin
      try
        strtoint64(value);
      except
        result:=false;
    end;然后在EDIT的ONchange里写代码
      

  18.   

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

  19.   

    上面的方法都一样,你还可以写个 exception
    try
       strtoint(edit1.text);
    except
       showmessage("只能输数字");
       edit1.text:='';
    end;
      

  20.   

    procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
        begin
          if not (key in ['0'..'9','.',#8]) then
          begin
            key:=#0;
            Messagebeep(0);
          end;
        end;
      

  21.   

    procedure Tfrmporeceipt.Edit3KeyPress(Sender: TObject; var Key: Char);
    begin
       //限定此文本框内只能输入数字,输入其余的符号则提示出错,#8表示 'Backspace'按键
        if not (Key in ['0', '9', '8', '7', '6', '5', '4', '3', '2', '1', '.', #8]) then begin
          Key := #0;
          Beep;
          Application.MessageBox('Only Input  Number!', 'SystemInformation',MB_ICONINFORMATION);
        end;
    end;