如何判断Edit组件中有没有输入空格字符(不一定是第一个字符)??或者如何让Edit中只能输入字母与数字但不能影响Edit原来的作用的!

解决方案 »

  1.   

    key preessif  key in ['0',['1],..........................] then 
    key=#0
    endif
      

  2.   

    if key in ['0'..'9'] then key := #0;
      

  3.   

    on key preessif Key not in ['0'..'9','a'..'z','A'..'Z',#8] then Key := #0
      

  4.   

    得~~ 来晚一步
    #8 就是键盘上地 Back Space 键。
      

  5.   

    procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
    begin
      if not(key in ['0'..'9']) then
      begin
      if not(key in ['a'..'z']) then
      begin
      if not(key in ['A'..'Z']) then
      begin
        Key:=chr(0);
        showmessage('输入错误,请输入数字或字母');
        end;
    end;
    end;
    end;
    end.
      

  6.   

    或这样也可:procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
    begin
    if  not (key in ['0'..'9','a'..'z','A'..'Z',#8]) then
    begin
    Key := #0;
        showmessage('输入错误,请输入数字或字母');
        end;
        end;
    end.