程序的登录框, 点击登录按钮事件:(operator操作员表) cmUserName:=mUserName.Text;
  cmPassword:=mPassword.Text;
  operator.Open;
  operator.SetKey;
  operator.FieldByName('username').AsString:=cmUserName;  if  not operator.GotoKey then  //奇怪,这里要加上not才能执行过去
  begin
    tmpPassword:=operator.FieldByName('Password').AsString;
    tmpDept:=operator.FieldByName('Dept').AsString;
     if (tmpPassword=cmPassword) and (length(tmpPassword)=length(cmPassWord)) then
        begin
          showmessage('登录成功');
          operator.Close;
          ModalResult:=mrAll;
          Close;
        end
      else
        begin
          Application.MessageBox('密码不对!','系统登录',mb_OK+mb_ICONQUESTION);
          digit:=digit+1;
          if digit>3 then
            begin
              ModalResult:=mrAll;
              operator.Close;
              Close;
              JXMainForm.Close;
            end;
          operator.Close;
end
-----------------------------------------------
为什么执行到if  not operator.GotoKey then 这里一定要加上not才能登录的过去,否则就登录不过去呢?(现在操作员表里面只有一条记录,一个操作员) 

解决方案 »

  1.   

    没有找到'username'=cmUserName的记录
    试试
    ////  if  not operator.GotoKey then  //奇怪,这里要加上not才能执行过去 
      if operator.Locate('username', cmUserName, []) then
      begin 
        tmpPassword:=operator.FieldByName('Password').AsString; 
        tmpDept:=operator.FieldByName('Dept').AsString; 
         if (tmpPassword=cmPassword) and (length(tmpPassword)=length(cmPassWord)) then 
            begin 
              showmessage('登录成功'); 
              operator.Close; 
              ModalResult:=mrAll; 
              Close; 
            end 
          else 
            begin 
              Application.MessageBox('密码不对!','系统登录',mb_OK+mb_ICONQUESTION); 
              digit:=digit+1; 
              if digit>3 then 
                begin 
                  ModalResult:=mrAll; 
                  operator.Close; 
                  Close; 
                  JXMainForm.Close; 
                end; 
              operator.Close; 
    end