2
I have this code that I use in a login screen, that when the user uses the correct password, it directs to the main screen, until then everything ok, works perfectly, but when I fecho
the application it displays a message from the code.
Invalid user name or password. If you have forgotten your password, please refer to the system administrator
procedure TFrmLogin.imgLoginClick(Sender: TObject);
var StrSqlLog, mensagem: String;
begin
sleep(500);
strSqlLog:= 'select u.*, p.* '+
'from usuario u inner join perfil p '+
'on u.nivel = p.id '+
'where u.nome = '+#39+
edtName.Text+
#39 + ' and u.senha = ' +
#39 + edtPass.Text + #39;
FrmHome.QueryLogin.Close;
FrmHome.QueryLogin.SQL.Clear;
FrmHome.QueryLogin.SQL.Add(strSqlLog);
FrmHome.QueryLogin.Open();
if FrmHome.QueryLogin.RecordCount = 1 then
begin
FreeAndNil(FrmLogin);
Application.CreateForm(TFrmhome, Frmhome);
Application.Run;
end;
if FrmHome.QueryLogin.RecordCount = 0 then
begin
mensagem:= 'Nome ou senha do usuário '+
'inválidos.' + #13 + #13 +
'Se você esqueceu sua '+
'senha, consulte ' + #13 +
'o administrador do sistema.';
Application.MessageBox(PChar
(mensagem),
'Login não autorizado',
MB_OK+MB_IconError);
edtName.Clear;
edtPass.Clear;
edtName.SetFocus;
end;
You may have assigned some other event to
procedure
imgLoginClick
, I’ve seen it happen while duplicating buttons on the screen, check it out.– David
@David has nothing in the form onclose,
– Guilherme Lima
Everything indicates that the process is being called at some other time. In the Onexit event of some Edit, for example.
– Reginaldo Rigo
It makes no sense because it enters the condition that the query has no record.
– Guilherme Lima
It does. It makes perfect sense. Select is based on edtName.Text and edtPass.Text. If the eEvent onExit of this field or any other event calls the method the query is mounted without user and password and of course, it will not find any record that meets these conditions.
– Reginaldo Rigo
Okay @Reginaldorigo, but I guarantee it’s not being used anywhere.
– Guilherme Lima
If they are not too long, post the PAS and DFM of that screen. To post the DFM with the form on the screen press ALT+F12 and post the code.
– Reginaldo Rigo
dfm is quite extensive.
– Guilherme Lima
Let’s go continue this discussion in chat.
– Reginaldo Rigo