在edit1的exit事件里如何判断,我是用回车键离开还是用其他方法离开的???程序怎么写,请大侠帮忙!!!

解决方案 »

  1.   

    if key=#13 then
     dosomething
    end;
      

  2.   

    声明一个boolean类型的全局变量useEnter,在edit的OnKeydown事件中改变这个值,根据useEnter的值不同来处理:例:
    procedure TForm1.FormCreate(Sender:TObject);
    begin
    useEnter:=flase
    end;//在Edit1的OnKeyDown中书写的代码:
    Proceduer TForm1.Edit1KeyDown;
    begin
    //如果敲了回车键,则
    if key=vk_return then
    begin
    useEnter:=true;
    edit2.setFocus;
    end
    else
    useEnter:=false;
    end;//在edit1的Onexit事件中书写代码:
    Proceduer TForm1.Edit1Exit(Sender:TObject);
    begin
    //如果useEnter不为真(即:不是用回车键),则不允许焦点离开文本框edit1,
    if not useEnter then
    edit1.setFocus;
    end;
      

  3.   

    if    key=#13\
    then  key :=#9;
     
    或者 if    key =#13 
         then  form1.setfocus :=exit_button;
    就是把当前窗体的焦点聚到exit_button 上
      

  4.   

    代码如下:procedure TForm1.Edit1Exit(Sender: TObject);
    begin
      if key=#13 then
        showmessage('aaaa');
    end;
    请问它怎么报:
     
    [Error] Unit1.pas(56): Undeclared identifier:'key'啊??
      

  5.   

    你的key又不是参数又不是局部变量,没有申明,你的EDIT的KEYPREE事件中做一个开关,用它在ONEXIT中判断
      

  6.   

    to  delphi_xizhousheng(西周生) :
    "你的EDIT的KEYPREE事件中做一个开关"  请问具体怎么做大,提示一下好吗??
      

  7.   

    就是在OnKeypress中if key=#13 then...
      

  8.   

    请问怎么把  exit事件 和  onkeypress事件 联系起来???
      

  9.   

    在onkeypress事件中写edit1.onexit(self)
      

  10.   

    TO: flylin(飞天) 
      "在onkeypress事件中写edit1.onexit(self)"
      这个怎么写,它们是两个事件啊?