在ONKEYPRESS事件中写
if not key in [0..9] then
  key :=#0;

解决方案 »

  1.   

    object MaskEdit1: TMaskEdit
      Left = 160
      Top = 80
      Width = 120
      Height = 21
      EditMask = '000000;1;_'
      MaxLength = 6
      TabOrder = 0
      Text = '      '
    end
      

  2.   

    少一段
        if Length(Edit1.Text) > 6 then
        Key :=#0;
      

  3.   

    设置edit1的MaxLength为6
    在OnKeyPress事件中添加以下代码:
         if not( key in ['0'..'9',#27,#13,#8])then
       key:=#0;
    或者用MaskEdit代替Edit。
      

  4.   

    用edit的maxlength就可以设置他的前多个数了
    edit1.maxlength:=6;还可以用label1.Caption :=inttostr(length(edit1.Text))得到他的个数
    再if一下不就可以了吗
    数字就可以用assci码来定了
      

  5.   

    onexit事件中写
    var
      f: integer;
    begin
      try
        f:=strtoint(edit1.text);
        if (f<100000) or (f>999999) then raise excption.create('out of range');
      except
        application.messagebox('reinpout!','error',mb_ok);
        edit1.setfocus;
      end;
    end
      

  6.   

    设置edit1的MaxLength为6
    在OnKeyPress事件中添加以下代码:
         if not( key in ['0'..'9',#8])then
       key:=#0;
      

  7.   

    设置edit1的MaxLength为6
    在Edit1的OnKeyPress事件中添加以下代码:
    if not( key in ['0'..'9'])then
       key:=#0;
      

  8.   

    把edit的maxlength设置为6,且在onkeypress事件中写入如下代码:
    if (not(key in ['0'..'9'])and(key<>#45)) then
      key :=#0;
    可以解决负数的。
      

  9.   

    建议用伴水说的用MASKEDIT方便使用!