如题!!

解决方案 »

  1.   

    procedure TForm.Edit1KeyPress(Sender: TObject; var Key: Char);
    begin
        if Key in ['0'..'9',#8,#13] = False then
        begin
            Application.MessageBox('只能输入数字! ','系统提示',MB_OK+MB_ICONWARNING);
            Edit1.SetFocus;
            Abort;
        end;
    end;
    //至于小数点,可以自己加控制
      

  2.   

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

  3.   

    如果用键值去控制麻烦,不仅仅要看是不是数字和点,还要看是不是已经有了点,所以这样吧
    try
      strtofloat(edit1.text);
    except
      edit1.text:='0';
    end
      

  4.   

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

  5.   

    function CheckInputNum(AStr: string; var Key: Char): Boolean;
      const NumberSet = ['0' .. '9', char(#8), char(#13), char(#46), '.', '-'];
    begin             
      if not (Key in NumberSet) then Key := #0;
      if (Key = '.') and ((Length(AStr) = 0) or (Pos('.', AStr) > 0)) then
        Key := #0;  if (Length(AStr) = 1) and (AStr[1] = '0') and (Key = '0') then Key := #0;
      Result := Key <> #0
    end;你可以在OnKeyPress中调用 
      

  6.   

    procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
    begin
      if  not (key in ['0'..'9','.',#13,#8]) then  key:=#0
    //只能用数字,".",回车(#13),退格(#8)
    end;
      

  7.   

    if  not (key in ['0'..'9','.',#13,#8]) then  key:=#0
    只是可以在这个EDIT中粘贴带有别的字符的东东
      

  8.   

    procedure Tjinhuo_frm.Edit3KeyPress(Sender: TObject; var Key: Char);
    begin
    if not (key in['0'..'9',#8]) then
      begin
        key:=#0;
        messagebeep(1);
        application.MessageBox('请输入数字!','提示!',mb_ok+mb_iconwarning);
       end;
    end;
    这样就可以实现了
      

  9.   

    晕哦,这个问题我这个菜鸟都回答了N次了在EDIT 的ONEXIT(当这个EDIT失去焦点的时候)写几句话
    try
      strtofloat(edit.text);
    except
      showmessage('error');
      edit.setfocus;
    end;还有就是在EDIT的ONKEYPRESS里添加对KEY的判断
    if not (key in ['0'..'9','.',#8,#13]) then
    key:=0;上面这个写法有问题的,就是无法控制小数点的位置和个数.
    所以在EDIT失去焦点的时候判断一下是很有必要的.除非你把错误的可能都排除了,禁止EDIT粘贴之类的,老问题了啊.期待高手写个这样EDIT的控件吧.呵呵,最好是免费的哦