Delphi程序访问冲突
请帮我解决以下代码。一旦我单击“登录”按钮,我就会收到来自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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
跳过 login.create 并将下一行更正为:
登录准备就绪时也应释放登录对象。
像这样 :
Skip login.create and correct next line to :
the login object should be freed when the login is ready as well.
Like this :