如何能Edit控件识别数字,如果输入的不是数字,就弹出错误提示。
比如
procedure TForm1.editwinred1zu1KeyPress(Sender: TObject; var Key: Char);
begin
  if key = #13 then
  begin
    if editwinred1zu1.Text = '' then
    begin
      application.MessageBox(pchar('数据是空值'),pchar('错误'),0);
      editwinred1zu1.SetFocus;
    end
    else if editwinred1zu1.Text = edit then
    begin
      application.MessageBox(pchar(''),pchar(''),0);
      editwinred1zu1.SetFocus;
    end
    else if not(strtoint(editwinred1zu1.Text)in[1..33])then
    begin
      application.MessageBox(pchar('数据不符,请输入1到33之间的数!'),pchar('错误'),0);
      editwinred1zu1.SetFocus;
    end
    else if editwinred1zu1.Visible = true then
    begin
      editwinred1zu1.Visible := false;
      lblwinred1zu1.Visible := true;
      lblwinred1zu1.Caption := editwinred1zu1.Text;
    end;
  end;
end;
以上代码是我的实际编程代码,功能基本完成,就只差识别数字的功能了。请求各位高手能多多指教!

解决方案 »

  1.   

    呵~~ 楼主啊, 刚才你发给我的站内短信我看了, 但是, 我忽然看见你又发了这样一贴.....难道上一贴,没有解决吗? 呵呵....麻烦您再去看一下上一贴吧.呵~~祝您学习进步http://community.csdn.net/Expert/topic/5294/5294925.xml?temp=.181225
      

  2.   

    procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
    begin
      if not (key in ['0'..'9',#8]) then
         begin
         key := #0;
         showmessage('警告:刚才的按键不是数字键!');
         end;
    end;
      

  3.   

    if not (Key in ['0'..'9']) then
      raise Exception.Create('输入的不是数字');
      

  4.   

    来晚拉
    dBASEIII(明年毕业了) 的答案好些
      

  5.   

    dBASEIII(明年毕业了) 的方法我试过了,不行啊
      

  6.   

    不行啊
    procedure TForm1.editwinred2zu5KeyPress(Sender: TObject; var Key: Char);
    begin
      if key = #13 then
      begin
        if not(editwinred2zu5.Text<>'')then
        begin
        application.MessageBox(pchar('数据是空值'),pchar('错误'),0);
        editwinred2zu5.SetFocus;
        end
        else if not(key in['0'..'9'])then
        begin
        application.MessageBox(pchar('数据不符,请输入数字'),pchar('错误'),0);
        end
        else if not(strtoint(editwinred2zu5.Text)in[1..33])then
        begin
        application.MessageBox(pchar('数据不符,请输入1到33之间的数!'),pchar('错误'),0);
        editwinred2zu5.SetFocus;
        end
        else if editwinred2zu5.Text <> '' then
        begin
        editwinred2zu5.Visible := false;
        lblwinred2zu5.Visible := true;
        lblwinred2zu5.Caption := editwinred2zu5.Text;
        end;
      end;
    end;
      

  7.   

    procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
    begin
      if not (key in ['0'..'9',#8]) then
         begin
         key := #0;
         showmessage('警告:刚才的按键不是数字键!');
         end;
    end;这样的就是对的
      

  8.   

    以上代码,不管输入的是否是数字,回车后都会出现这段代码的效果!
        else if not(key in['0'..'9'])then
        begin
        application.MessageBox(pchar('数据不符,请输入数字'),pchar('错误'),0);
        end
      

  9.   

    建议你看看你写的代码逻辑有没有问题。procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
    begin
      if not (key in ['0'..'9',#8]) then
         begin
         key := #0;
         showmessage('警告:刚才的按键不是数字键!');
         end;
    end;这样的就是对的
      

  10.   

    你这句是什么意思??????    if not(editwinred2zu5.Text<>'')then
        begin
        application.MessageBox(pchar('数据是空值'),pchar('错误'),0);
        editwinred2zu5.SetFocus;
        end
      

  11.   

    if not(key in ['0'..'9',#8,#13]) then
          key:=#0
        else
        if key = #13 then
        begin
            if trim(Edit1.Text)='' then
               MessageBox(Application.Handle,'数据不能为空','提示',MB_OK)
            else
            if not(strtoint(Edit1.Text)in[1..33])then
            begin
                    application.MessageBox(pchar('数据不符,请输入1到33之间的数!'),pchar('错误'),0);
                    Edit1.SetFocus;
            end;
        end;
      

  12.   

    问题是解决了,可是,如何让edit控件先输入,然后再进行判断是否是数字,如果不是数字就是出现错误提示