如题

解决方案 »

  1.   

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

  2.   

    小数点也可以用这个方法!
    如果你是想输入IP地址的话
    可以下载专门的控件!
    他好像是Windows的标准窗口类
      

  3.   

    procedure TfrmRunStatistic.edtSpaceKeyPress(Sender: TObject;
      var Key: Char);
    begin
      if (not (Key in ['0'..'9'])) and (Key <> '.') and (Key <> chr(8)) then
        Key := chr(0);
    end;我觉得你还有必要加上回退键,这样就可以让用户修改了。
      

  4.   

    我怎样使用虚拟键?VK_O,VK_BACKSPACE,VK_9 ...?
    我用过,老是报错:类型不匹配,怎么办?
      

  5.   

    try
      StrToFloat(jvfloatedit1.text);
      except
      postmessage(jvfloatedit1.handle,wm_keydown,vk_back,0);
       end;
      

  6.   

    在keydown里可以使用虚拟键,
    在keypress里需要转换一下 Word(Key) = VK_BACKSPACE
      

  7.   

    procedure TForm_QueryBill.ComPTextKeyPress(Sender: TObject; var Key: Char);
    begin
      if Assigned(CurField) then
      begin
        if (CurField.DataType in [ftFloat, ftCurrency, ftBCD]) then
        begin
          if not ((key in ['0'..'9', '.', '-', #8])) then
          begin
            key := #0
          end
          else
          begin
            if (Key = '.') and (Pos('.', TEdit(Sender).Text) <> 0) then
              Key := #0
            else if
              (Key = '-') and (Pos('-', TEdit(Sender).Text) <> 0) then
              Key := #0;
          end;
        end
        else if (CurField.DataType in [ftAutoInc, ftSmallint, ftInteger, ftWord,
          ftBytes, ftLargeint]) then
        begin
          if not ((Key in ['0'..'9', '-', #8])) then
          begin
            Key := #0
          end
          else
          begin
            if (Key = '-') and (Pos('-', TEdit(Sender).Text) <> 0) then
              Key := #0;
          end;
        end
        else
          Exit;
      end;
    end;
      

  8.   

    if not (key in ['0'..'9',#8],'.')  then
       begin
          if (key='.') and (pos('.',Tedit(sender).Text)=0) then exit;
          key:=#0;
          showmessage('必须填入数字!');
       end;
      

  9.   

    同意楼上的各位,就是这样,
    编写代码,在keydown 事件中编写代码 ……进行判断