procedure TForm.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
    if Not (Key in ['1','2','3','4','5','6','7','8','9','0',chr(8)]) then
    begin
      Key := #0;
      exit;
    end;
  if Edit1.Text='' then exit;   //这里  我想在edit1里写数字 然后计算一些东西  可是要是edit1里只有一位数字的时候,Edit1.Text老是为空    要怎么办啊???
  ...
  ...end;

解决方案 »

  1.   

    此时,KEY的值还没有写入EDIT的TEXT属性,当然为空了。你在这个事件里写判断是有错误的!!
      

  2.   

    同意白雪公猪如果是方向键,DEL,怎么办,好象没有处理
      

  3.   

    begin
      if not (Key in ['0'..'9']) then
      begin
        key:=#0;
        exit;
      end;
    end;
      

  4.   

    你可以放在Edit1失复查焦点的时候写,----------------------
      if Edit1.Text='' then exit;   //这里  我想在edit1里写数字 然后计算一些东西  可是要是edit1里只有一位数字的时候,Edit1.Text老是为空    要怎么办啊???
      

  5.   

    如果EDIT不想为空的话,你在它失去焦点的时候写判断如:procedure TFrm1.Edit1Exit(Sender: TObject);
    begin
      if Trim(Edit1.Text) <> '' then
          exit;
    end;就可以了。
      

  6.   

    不好意思,把‘<>’改为‘=’打错了。
      

  7.   

    可是我后面要进行计算啊  要是不能用edit1.text的话   那只能用key了??
    可是key又很不方便  并且我画的那个窗体 要用Edit1Exit事件 几乎不行还有别的方法能让别人在写完字后  按确定按钮前就能计算出想要的结果吗?
      

  8.   

    你可以这样:
    比如你要算 a * b = c;
    a 即edit1procedure tform1.edit1keypress(...)
    begin
      if key in ['0'..'9'] then
        c := strtoint(edit1.text) * b;
    end;
      

  9.   

    if key = #13 then//当按下回车后
    {计算代码}不知道是不是楼主的意思
      

  10.   

    TForm.Edit1KeyPress
    表示在按键盘的时候触发,所以此时的edit.text内容还没有接受到键盘输入的key 值
    你的
    if Edit1.Text='' then exit;
    在Edit1.Text='' 是没有意义的