如上

解决方案 »

  1.   

    if key in ['0'..'9', ','] then
    ....
      

  2.   

    if not (key in [#48..#57,#8,#13,#46]) then
    begin
        key := #0;
        showmessage('请输入数字!');
    end;
      

  3.   

    if not (key in ['0'..'9','.',#8]) then key:=#0
    其中#8是删除键,肯定要允许输入的。key:=#0就是屏蔽掉你的输入。OVER
      

  4.   

    procedure CheckEditInput(Edit: Tedit; allowInput: integer = 1; OtherAllow: string = '');
    {allowInput
      1   数字
      2  小写
      4  大写
    }
    var InputStr, lstStr: string;
      lstChr: Char;
      selstrt: integer;
      canInput: bool;
    begin
      Edit.Text := Trim(Edit.Text);
      inputStr := Edit.Text;
      selstrt := Edit.SelStart;
      if length(inputStr) > 0 then
      begin
        lstStr := (copy(inputstr, selstrt, 1));
        lstChr := lstStr[1];
        case allowInput of
          1: canInput := isNumberChar(lstChr);
          2: canInput := IsLowerChar(lstChr);
          3: canInput := IsLowerChar(lstChr) or IsLowerChar(lstChr);
          4: canInput := IsUpperChar(lstChr);
          5: canInput := IsUpperChar(lstChr) or isNumberChar(lstChr);
          6: canInput := IsUpperChar(lstChr) or IsLowerChar(lstChr);
          7: canInput := IsUpperChar(lstChr) or IsLowerChar(lstChr) or isNumberChar(lstChr);    else canInput := true;
        end;
        if OtherAllow <> '' then
          canInput := canInput or (pos(lstChr, OtherAllow) > 0);
        if not canInput then
        begin
          Edit.Text := copy(inputstr, 1, selstrt - 1)
            + copy(inputstr, selstrt + 1, length(inputstr) - selstrt);
          Edit.SelStart := selstrt - 1;
        end;
      end;
    end;
      

  5.   

    这个你可以这样做unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        Edit1: TEdit;
        procedure Edit1KeyPress(Sender: TObject; var Key: Char);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}
    //这里是主要代码
    procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
    begin
        if pos(key,'0123456789.' +#8)=0 then
        key:=#0;
    end;end.
      

  6.   

    用key相关事件无法阻止拷贝进去的非法值
      

  7.   

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