界面:                 用户号:   edit1
                       用户名:   edit2 (这项不输的,自动返回数据的)
                       用户密码: edit3   运行可以,但是按下回车键没反应,不会跳到edit3上,edit2上也不显示内容。鼠标点击输入正确内容也可以进入第二个窗体。procedure TFrmdr.Edit1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
 if key=13 then    //当edit1敲下回车时,edit2返回数据库中的字段内容,并且edit3得到焦点。
 begin
  edit2.Text :=table1.fieldbyname('yhm').Value ;
  edit3.SetFocus ;
 end;
end;procedure TFrmdr.Edit3KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
 if key=13 then
  begin
  bitbtn1.SetFocus ;
  end;
end;
procedure TFrmdr.BitBtn1Click(Sender: TObject);
begin
  with table1 do
  begin
    if (edit1.Text ='') then
      begin
        application.MessageBox('工号或密码不能为空,请正确输入!','提示',mb_ok);
      end
       else
         begin
          if (edit1.Text <>'')and (edit3.Text <>'') then
            begin
              open;
                if locate('yhh;yhmm',vararrayof([edit1.text,edit3.text]),[])=true then
                  begin
                   Form2.caption:=form2.caption + form1.Label1 .caption+form1.Edit2 .text;
                   form2.show;
                   form1.Hide ;
                   form1.Free ;
                  end
                  else
                  showmessage('工号或密码有误!')
            end;
       end;
  end;
end;end.

解决方案 »

  1.   

    好象是可以的。改成这样:
    procedure TFrmdr.Edit3KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    begin
       if key=13 then
       begin
          BitBtn1Click(Sender);
       end;
    end;
      

  2.   

    用Key = VK_RETURN判断吧,不要用13
      

  3.   

    with table1 do
      begin
        if (edit1.Text ='') then
        begin
          application.MessageBox('工号或密码不能为空,请正确输入!','提示',mb_ok);
          Exit;
        end;
        
        if (edit1.Text = '') or (edit3.Text = '') then Exit;    open;
        if not locate('yhh;yhmm',vararrayof([edit1.text,edit3.text]),[]) then
        begin
          showmessage('工号或密码有误!');
          Exit;
        end;    Form2.caption:=form2.caption + form1.Label1 .caption+form1.Edit2 .text;
        form2.show;
        form1.Hide ;
        form1.Free ;
     end;
      

  4.   

    你这样写在Edit3里要回车两下才能执行到按钮的事件,跟踪一下按钮事件有没有被执行。如果要只按一次回车,可以按gzmhero(hihihi)那样写
      

  5.   

    在这里先谢过大家了,方法都用过了,还是不行啊!帮帮忙啊!
    上面的方法都用过了,还是不行。
    用g961681(PerryWang)的方法,不报错,但是也运行不了。
    按gzmhero(hihihi)那样写,就会报错。
      

  6.   

    在 KeyPress 事件里  if key=#13 then
                             begin
                             
                             end;
      

  7.   

    回复人: surdon(ャ野马ャ) ( ) 信誉:97 
    同意,你试下应该有用的
      

  8.   

    原因出在BITBTN1上。 你把它的DEFAULT属性设为FALSE。然后把它的MODELRESULT设为NONE。
    应该就可以了。
    因为你按下回车后,被BITBTN1抢了过去,并没有触发你的EDIT1。KEYPRESS事件。
      

  9.   

    顶~~
    很有可能就是coffee36(咖啡)说的那个原因,呵呵,经验解决问题。
      

  10.   

    procedure TFrmdr.Edit1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    begin
     if key=13 then    //改为 if key = #13 then
     begin
      edit2.Text :=table1.fieldbyname('yhm').Value ; //改为  edit2.Text := table1.FieldByName('yhm').AsString;
      edit3.SetFocus ;
     end;
    end;
      

  11.   

    谢谢大家的帮忙!都用了,
    用coffee36(咖啡)的方法,敲回车时会跳到edit3上(当我把procedure TFrmdr.Edit1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    begin
     if key=13 then    
     begin
      edit2.Text :=table1.fieldbyname('yhm').Value ;//当把这条注掉,就不会报错,会跳到edit3上,输入密码后可以进入系统。但是将此句一恢复就报错。
      edit3.SetFocus ;
     end;
    end;报错:project project1.exe raised exception class EDatabaseError with message 'table1:field'yhm' not found'.
          process stopped,use step or run to continue.
      

  12.   

    是这句出错的平
    edit2.Text :=table1.fieldbyname('yhm').Value ;//当把这条注掉,就不会报错,会跳到那个是说没有找到'yhm' 这个字段,确定没有写错数据库表中字段 并且建议 用edit2.Text :=table1.fieldbyname('yhm').asstring  (如果这个字段为空,用value就会出错)并建议使用异常捕获try 
    ...
    catch
    end;
      

  13.   

    应该检查一下你的数据库里有没有yhm这个字段才对啊
      

  14.   

    我检查了,有啊。我是用SQL 2000做的后台数据库
      

  15.   

    用我最初的方法,运行时就是敲回车没反映,不会到edit3上,但是按TAB键或用鼠标点到edit3上输入密码,是可以进入系统的。也不会报错。就是姓名的地方不不会返回我要的内容。