Delphi程序访问冲突

发布于 2024-11-30 14:02:48 字数 2706 浏览 3 评论 0原文

请帮我解决以下代码。一旦我单击“登录”按钮,我就会收到来自delphi的访问冲突......由!!!指示

登录单位

unit Log;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls,cls_LogIn,Jpeg;

type
  TForm2 = class(TForm)
    lbllogIn: TLabel;
    pnlSplitter: TPanel;
    edtUserName: TEdit;
    edtPassword: TEdit;
    lblUserName: TLabel;
    lblPassword: TLabel;
    btnLogIn: TButton;
    btnRegister: TButton;
    lblRegister: TLabel;
    edtRegName: TEdit;
    edtRegSurname: TEdit;
    edtRegPassword: TEdit;
    edtCountry: TEdit;
    edtHomelanguage: TEdit;
    btnRegisterF: TButton;
    btnCancel: TButton;
    lblRegName: TLabel;
    lblRegSurname: TLabel;
    lblRegPassword: TLabel;
    lblCountry: TLabel;
    lblHomelanguage: TLabel;
    imgLinks: TImage;
    imgRegs: TImage;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure btnLogInClick(Sender: TObject);
  private

  public

    { Public declarations }
  end;

var
  Form2: TForm2;
  Login : Tlogin;
implementation

uses Main;

{$R *.dfm}

procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Application.Terminate;

end;

procedure TForm2.btnLogInClick(Sender: TObject);   **!!!!!!!!**
var

bUser,bPassword : Boolean;
sUser,sPassword,sMessage : string;
begin
  form1.qrymain.close  ;
Form1.Qrymain.sql.text := 'select * from Gebruikers';
form1.qryMain.open;

sUser := edtUserName.Text;
sPassword := edtpassword.text;
bUser :=  form1.qrymain.locate('Username',sUser,[]);
bPassword := form1.qrymain.locate('Password',sPassword,[]);
Login.create;
login.create(sUser,sPassword,bUser,bPassword);
sMessage:= Login.toetslog;
ShowMessage(sMessage);

end;

类别单位:

unit cls_LogIn;

interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Menus, StdCtrls, Buttons, math, ExtCtrls;
type
Tlogin = class(Tobject)

private

Fepos :string ;
fwagwoord :string ;
Fbepos : Boolean;
fbwagwoord : Boolean;
public
constructor create; overload;
constructor Create(epos,wagwoord:String;bepos, bwagwoord: boolean); overload; 

function toetslog: string;


end;
implementation

{ Tlogin }



constructor Tlogin.Create(epos, wagwoord: String;bepos, bwagwoord: boolean);
begin
fepos := epos ;
fwagwoord := wagwoord ;
fbepos := bepos;
fbwagwoord := bwagwoord;
end;


constructor Tlogin.create;
begin
 fepos:= ' ';
 fwagwoord := ' ';
 fbepos := false;
 fbwagwoord := true;
end;

function Tlogin.toetslog;
begin

if (fbepos = True) and (fbwagwoord = True)
then
begin
result := 'Welcome '+' '+fepos
 end
else
result := 'SORRY VERKEERD HEHE'+' '+fwagwoord ;
end;


end.
end.

Please help me with the following code. I get a Access violation from delphi once I click the Log IN button.... Indicated by the !!!

LogIn Unit

unit Log;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls,cls_LogIn,Jpeg;

type
  TForm2 = class(TForm)
    lbllogIn: TLabel;
    pnlSplitter: TPanel;
    edtUserName: TEdit;
    edtPassword: TEdit;
    lblUserName: TLabel;
    lblPassword: TLabel;
    btnLogIn: TButton;
    btnRegister: TButton;
    lblRegister: TLabel;
    edtRegName: TEdit;
    edtRegSurname: TEdit;
    edtRegPassword: TEdit;
    edtCountry: TEdit;
    edtHomelanguage: TEdit;
    btnRegisterF: TButton;
    btnCancel: TButton;
    lblRegName: TLabel;
    lblRegSurname: TLabel;
    lblRegPassword: TLabel;
    lblCountry: TLabel;
    lblHomelanguage: TLabel;
    imgLinks: TImage;
    imgRegs: TImage;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure btnLogInClick(Sender: TObject);
  private

  public

    { Public declarations }
  end;

var
  Form2: TForm2;
  Login : Tlogin;
implementation

uses Main;

{$R *.dfm}

procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Application.Terminate;

end;

procedure TForm2.btnLogInClick(Sender: TObject);   **!!!!!!!!**
var

bUser,bPassword : Boolean;
sUser,sPassword,sMessage : string;
begin
  form1.qrymain.close  ;
Form1.Qrymain.sql.text := 'select * from Gebruikers';
form1.qryMain.open;

sUser := edtUserName.Text;
sPassword := edtpassword.text;
bUser :=  form1.qrymain.locate('Username',sUser,[]);
bPassword := form1.qrymain.locate('Password',sPassword,[]);
Login.create;
login.create(sUser,sPassword,bUser,bPassword);
sMessage:= Login.toetslog;
ShowMessage(sMessage);

end;

Class Unit:

unit cls_LogIn;

interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Menus, StdCtrls, Buttons, math, ExtCtrls;
type
Tlogin = class(Tobject)

private

Fepos :string ;
fwagwoord :string ;
Fbepos : Boolean;
fbwagwoord : Boolean;
public
constructor create; overload;
constructor Create(epos,wagwoord:String;bepos, bwagwoord: boolean); overload; 

function toetslog: string;


end;
implementation

{ Tlogin }



constructor Tlogin.Create(epos, wagwoord: String;bepos, bwagwoord: boolean);
begin
fepos := epos ;
fwagwoord := wagwoord ;
fbepos := bepos;
fbwagwoord := bwagwoord;
end;


constructor Tlogin.create;
begin
 fepos:= ' ';
 fwagwoord := ' ';
 fbepos := false;
 fbwagwoord := true;
end;

function Tlogin.toetslog;
begin

if (fbepos = True) and (fbwagwoord = True)
then
begin
result := 'Welcome '+' '+fepos
 end
else
result := 'SORRY VERKEERD HEHE'+' '+fwagwoord ;
end;


end.
end.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

生活了然无味 2024-12-07 14:02:48

跳过 login.create 并将下一行更正为:

login := TLogin.Create(sUser,sPassword,bUser,bPassword);

登录准备就绪时也应释放登录对象。

像这样 :

login := TLogin.Create(sUser,sPassword,bUser,bPassword);
try
  sMessage := login.toetslog;
  ShowMessage(sMessage);
finally
  login.free;
end;

Skip login.create and correct next line to :

login := TLogin.Create(sUser,sPassword,bUser,bPassword);

the login object should be freed when the login is ready as well.

Like this :

login := TLogin.Create(sUser,sPassword,bUser,bPassword);
try
  sMessage := login.toetslog;
  ShowMessage(sMessage);
finally
  login.free;
end;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文