1,procedure edit1.onkeypress(..)
begin
  if not (key in ['0'..'9',chr(8),chr(13)]) then 
  ShowMessage('this is not int');
  Edit1.text:='';
end;
为什么这样不能使Edit1.text为空。这样后它只能输入一位数字了??
为什么?
请教!

解决方案 »

  1.   

    procedure edit1.onkeypress(..)
    begin
      if not (key in ['0'..'9',chr(8),chr(13)]) then 
      ShowMessage('this is not int');
      Key:=#0;
      Edit1.text:='';
    end;
      

  2.   

    我想你的意思是当输入的键盘编码不在〔'0'..'9',chr(8),chr(13)〕这个集合的时候 把Edit1.text清空  是么?
    begin
      if not (key in ['0'..'9',chr(8),chr(13)]) then 
      begin
      ShowMessage('this is not int');
      Edit1.text:='';
      end;
    end;
      

  3.   

    同意楼上用begin和end把语句块括起来!
      

  4.   

    if not (key in ['0'..'9',chr(8),chr(13)]) then 
     begin
      ShowMessage('this is not int');
      Edit1.text:='';
      Key := #0;
     end;关键在于Key := #0;
      

  5.   

    楼主的意思是不让输入不是数字的字符,你只要把EIDT.TEXT=''去掉并加上KEY:=#0;就可以了
      

  6.   

    难道clear不能清空么?edit.clear;
      

  7.   

    如果想输入无效,key:=#0 肯定没错。
    edit.text:='' 表示清空。
      

  8.   

    同意楼上的观点。清空用 edit.text:='' 肯定可以的。
      

  9.   

    不括号起来 肯定每次都edit.text='' 了
    少括号,清空 edit.text=''够了
      

  10.   

    少了一個end,說成括號了,不好意思