1
Guys I have a problem, I’m beginner in Delphi and I am developing a registration and consultation system, it is almost finished, I am doing the login part of the system, where only registered users will have access.
But by entering the user and password and clicking login is giving me the following error
Raised Exception class $C0000005 with message - Acess Violation at 0x008ebfd5: read of address 0x000001a0
Could someone give me a hand there? I searched and saw that this error is caused when using an object that has not been instantiated or that has already been destroyed, I debugged and it returns me the line 37 that contains:
with Dtm.fdquery_Login do
unit Unt_Login;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Buttons;
type
Tfrm_Login = class(TForm)
edt_Usuario: TEdit;
Label1: TLabel;
edt_Senha: TEdit;
Label2: TLabel;
bbtn_Entrar: TBitBtn;
bbtn_Cancelar: TBitBtn;
procedure bbtn_EntrarClick(Sender: TObject);
procedure edt_SenhaChange(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frm_Login: Tfrm_Login;
implementation
{$R *.dfm}
uses
Unt_Dtm;
procedure Tfrm_Login.bbtn_EntrarClick(Sender: TObject);
begin
with dtm.fdquery_Login do
begin
Close;
SQL.Clear;
SQL.Add('SELECT * FROM tb_Usuario WHERE user_login = :login AND user_senha = :senha');
ParamByName('login').AsString := edt_Usuario.Text;
ParamByName('senha').AsString := edt_Senha.Text;
Open;
if RecordCount > 0 then
begin
if (Time >= StrToTime('00:00:00')) and (Time < StrToTime('11:59:59')) then
begin
Application.MessageBox('Olá :bom_dia_nome_usuario bom dia, seu acesso ao sistema foi liberado', 'Seja bem vindo(a)', MB_OK);
ParamByName('bom_dia_nome_usuario').Value := dtm.fdquery_Loginuser_nome.AsString;
end;
if (Time >= StrToTime('12:00:00')) and (Time < StrToTime('17:59:59')) then
begin
Application.MessageBox('Olá :boa_tarde_nome_usuario boa tarde, seu acesso ao sistema foi liberado', 'Seja bem vindo(a)', MB_OK);
ParamByName(':boa_tarde_nome_usuario').Value := dtm.fdquery_Loginuser_nome.AsString;
end;
if (Time >= StrToTime('18:00:00')) and (Time < StrToTime('23:59:59')) then
begin
Application.MessageBox('Olá :boa_noite_nome_usuario boa noite, seu acesso ao sistema foi liberado', 'Seja bem vindo(a)', MB_OK);
ParamByName(':boa_noite_nome_usuario').Value := dtm.fdquery_Loginuser_nome.AsString;
end;
frm_Login.Close;
end
else
begin
Application.MessageBox('Usuário ou Senha inválidos', 'Dados inválidos', MB_OK + MB_ICONERROR);
Exit;
end;
end;
end;
procedure Tfrm_Login.edt_SenhaChange(Sender: TObject);
begin
edt_Senha.PasswordChar := '*';
end;
end.
Thank you very much for the answer Junior, it was very helpful!
– Magno
I recommend not using
with
, at first glance can even save on typing but on aprocedure
great Delphi may lose reference and including thedtm.fdquery_Login
explicitly clarifies the code for future change.– leogregianin