procedure TfmLogin.btnOkClick(Sender: TObject); var sConnectionString, sSqlString: string; begin if Length(Trim(cbSqlServerName.Text)) <> 0 then if Length(Trim(edtUserName.Text)) <> 0 then begin fmLogin.Cursor := crHourGlass; sConnectionString := 'Provider=SQLOLEDB.1;Persist Security Info=True;User ID=' + Trim(edtUserName.Text) + ';Initial Catalog=Northwind;Data Source=' + cbSqlServerName.Text + ';Password=' + edtPassword.Text; dmAllWeb.ADOConnection1.ConnectionString := sConnectionString; try dmAllWeb.ADOConnection1.Connected := True; with dmAllWeb.ADOStoredProc1 do begin Close; ProcedureName:='LoginInformation'; parameters.Clear; Parameters.Refresh(); Parameters.CreateParameter('@ClientName',ftstring,pdInput,20,0); Parameters.CreateParameter('@Password',ftstring,pdInput,20,0); Parameters.CreateParameter('@MachineId',ftstring,pdInput,23,0); Parameters.CreateParameter('@VersionNum',ftstring,pdInput,13,0); Parameters.CreateParameter('@LoginMessage',ftinteger,pdOutput,1,0); Prepared; Parameters.ParamByName('@ClientName').Value := Trim(edtUserName.Text); Parameters.ParamByName('@Password').Value := Trim(edtPassword.Text); Parameters.ParamByName('@MachineId').Value := MachineID1.GetMachineID; Parameters.ParamByName('@VersionNum').Value := Label7.Caption; ExecProc; case Parameters.ParamByName('@LoginMessage').Value of 0: begin Application.MessageBox('用户不存在!','错误', MB_OK or MB_ICONERROR); edtUserName.SetFocus; exit; end; 1: begin Application.MessageBox('密码错误!请重新输入密码!','错误', MB_OK or MB_ICONERROR); edtUserName.SetFocus; exit; end; 2: begin end; 3: begin Application.MessageBox('该用户已注册在另一台电脑上!','错误', MB_OK or MB_ICONERROR); edtUserName.SetFocus; end; 4: begin end; 5: begin fmAllWeb.MenuImorptData.Visible := true; fmAllWeb.MenuAddClient.Visible := true; end; 6: begin Application.MessageBox('该帐号被锁定!','错误', MB_OK or MB_ICONERROR); edtUserName.SetFocus; end; end; end; except on e: EOleException do begin dmAllWeb.ADOConnection1.Connected := False; Application.MessageBox(pchar(E.Message),'错误', MB_OK or MB_ICONERROR); end; end; end else begin Application.MessageBox('请输入帐号!','错误', MB_OK or MB_ICONERROR); edtUserName.SetFocus; exit; end else begin Application.MessageBox('登陆服务器必须输入!','错误', MB_OK or MB_ICONERROR); cbSqlServerName.SetFocus; exit; end;
exit;
跳出,不运行下面的代码
var
sConnectionString, sSqlString: string;
begin
if Length(Trim(cbSqlServerName.Text)) <> 0 then
if Length(Trim(edtUserName.Text)) <> 0 then
begin
fmLogin.Cursor := crHourGlass; sConnectionString := 'Provider=SQLOLEDB.1;Persist Security Info=True;User ID=' + Trim(edtUserName.Text) + ';Initial Catalog=Northwind;Data Source=' + cbSqlServerName.Text + ';Password=' + edtPassword.Text; dmAllWeb.ADOConnection1.ConnectionString := sConnectionString; try
dmAllWeb.ADOConnection1.Connected := True; with dmAllWeb.ADOStoredProc1 do
begin
Close;
ProcedureName:='LoginInformation'; parameters.Clear;
Parameters.Refresh(); Parameters.CreateParameter('@ClientName',ftstring,pdInput,20,0);
Parameters.CreateParameter('@Password',ftstring,pdInput,20,0);
Parameters.CreateParameter('@MachineId',ftstring,pdInput,23,0);
Parameters.CreateParameter('@VersionNum',ftstring,pdInput,13,0);
Parameters.CreateParameter('@LoginMessage',ftinteger,pdOutput,1,0);
Prepared; Parameters.ParamByName('@ClientName').Value := Trim(edtUserName.Text);
Parameters.ParamByName('@Password').Value := Trim(edtPassword.Text);
Parameters.ParamByName('@MachineId').Value := MachineID1.GetMachineID;
Parameters.ParamByName('@VersionNum').Value := Label7.Caption; ExecProc; case Parameters.ParamByName('@LoginMessage').Value of
0: begin
Application.MessageBox('用户不存在!','错误', MB_OK or MB_ICONERROR);
edtUserName.SetFocus;
exit;
end;
1: begin
Application.MessageBox('密码错误!请重新输入密码!','错误', MB_OK or MB_ICONERROR);
edtUserName.SetFocus;
exit;
end;
2: begin end;
3: begin
Application.MessageBox('该用户已注册在另一台电脑上!','错误', MB_OK or MB_ICONERROR);
edtUserName.SetFocus;
end;
4: begin
end;
5: begin
fmAllWeb.MenuImorptData.Visible := true;
fmAllWeb.MenuAddClient.Visible := true;
end;
6: begin
Application.MessageBox('该帐号被锁定!','错误', MB_OK or MB_ICONERROR);
edtUserName.SetFocus;
end;
end; end;
except
on e: EOleException do
begin
dmAllWeb.ADOConnection1.Connected := False;
Application.MessageBox(pchar(E.Message),'错误', MB_OK or MB_ICONERROR);
end;
end;
end
else
begin
Application.MessageBox('请输入帐号!','错误', MB_OK or MB_ICONERROR);
edtUserName.SetFocus;
exit;
end
else
begin
Application.MessageBox('登陆服务器必须输入!','错误', MB_OK or MB_ICONERROR);
cbSqlServerName.SetFocus;
exit;
end;
刚才试了一下,edtUserName.SetFocus没错,是按照程序运行的,没有出现你说的问题
你设断点,F8单步调试一下,看看是不是其他原因