DELPHI7开发的程序出现EAccessViolation错误是怎么回事?
unitFormLogin;interfaceusesWindows,Messages,SysUtils,Variants,Classes,Graphics,Contro...
unit FormLogin;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, ADODB;
type
Tlogin = class(TForm)
Edit1: TEdit;
Label1: TLabel;
Label2: TLabel;
Edit2: TEdit;
Button1: TButton;
ADOQuery1: TADOQuery;
Edit3: TEdit;
Label3: TLabel;
procedure Button1Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure Edit2KeyPress(Sender: TObject; var Key: Char);
procedure Edit3Exit(Sender: TObject);
procedure Edit3KeyPress(Sender: TObject; var Key: Char);
private
{ Private declarations }
public
{ Public declarations }
end;
var
login: Tlogin;
implementation
uses formmain;
{$R *.dfm}
//输入编号自动显示用户名
procedure Tlogin.Edit3Exit(Sender: TObject);
begin
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select 姓名 from 用户清单 where 用户编号='''+edit3.Text+'''');
adoquery1.Open;
edit1.Text:=adoquery1.fieldbyname('姓名').AsString;
end;
//输入编号后回车,跳到帐号输入框
procedure Tlogin.Edit3KeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then { 判断是按执行键}
begin
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select 姓名 from 用户清单 where 用户编号='''+edit3.Text+'''');
adoquery1.Open;
edit1.Text:=adoquery1.fieldbyname('姓名').AsString;
end;
end;
//光标在密码框上时可按enter键执行查询
procedure Tlogin.Edit2KeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then { 判断是按执行键}
button1.Click;
end;
//用户名和密码校验登录系统
procedure Tlogin.Button1Click(Sender: TObject);
var
user,pass,temp:string;
begin
//根据用户输入的密码和帐号进行查询
//保存用户输入的帐号和密码
user:=edit1.Text;
pass:=Edit2.Text;
//将原来的SQL语句清除后再添加新的SQL语句
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Text:='select 用户编号 from 用户清单 where 姓名='''+user+'''and 密码='''+pass+'''';
Adoquery1.Open;
temp:=adoquery1.FieldByName('用户编号').AsString;
if temp<>'' then
//如果输入了正确的用户名和密码,那么必然能查到用户编号,否则结果为空
//登录成功,在管理窗体的状态栏上标示登录的用户名
begin
main.Visible:=true;
main.StatusBar1.Panels[0].Text:=user;
login.Hide;
end
//登录失败,提示用户重新输入
else
begin
ShowMessage('用户名或密码错误,请检查后重新登录');
end
end;
//登录窗口再次显示时,清空原来输入的用户名和密码
procedure Tlogin.FormShow(Sender: TObject);
begin
edit1.Clear;
edit2.Clear;
end;
end.
program JXGL;
uses
Forms,
FormLogin in 'FormLogin.pas' {Form1};
{$R *.res}
begin
Application.Initialize;
Application.Title := '教学管理系统';
Application.CreateForm(Tlogin, login);
Application.Run;
end. 展开
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, ADODB;
type
Tlogin = class(TForm)
Edit1: TEdit;
Label1: TLabel;
Label2: TLabel;
Edit2: TEdit;
Button1: TButton;
ADOQuery1: TADOQuery;
Edit3: TEdit;
Label3: TLabel;
procedure Button1Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure Edit2KeyPress(Sender: TObject; var Key: Char);
procedure Edit3Exit(Sender: TObject);
procedure Edit3KeyPress(Sender: TObject; var Key: Char);
private
{ Private declarations }
public
{ Public declarations }
end;
var
login: Tlogin;
implementation
uses formmain;
{$R *.dfm}
//输入编号自动显示用户名
procedure Tlogin.Edit3Exit(Sender: TObject);
begin
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select 姓名 from 用户清单 where 用户编号='''+edit3.Text+'''');
adoquery1.Open;
edit1.Text:=adoquery1.fieldbyname('姓名').AsString;
end;
//输入编号后回车,跳到帐号输入框
procedure Tlogin.Edit3KeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then { 判断是按执行键}
begin
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select 姓名 from 用户清单 where 用户编号='''+edit3.Text+'''');
adoquery1.Open;
edit1.Text:=adoquery1.fieldbyname('姓名').AsString;
end;
end;
//光标在密码框上时可按enter键执行查询
procedure Tlogin.Edit2KeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then { 判断是按执行键}
button1.Click;
end;
//用户名和密码校验登录系统
procedure Tlogin.Button1Click(Sender: TObject);
var
user,pass,temp:string;
begin
//根据用户输入的密码和帐号进行查询
//保存用户输入的帐号和密码
user:=edit1.Text;
pass:=Edit2.Text;
//将原来的SQL语句清除后再添加新的SQL语句
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Text:='select 用户编号 from 用户清单 where 姓名='''+user+'''and 密码='''+pass+'''';
Adoquery1.Open;
temp:=adoquery1.FieldByName('用户编号').AsString;
if temp<>'' then
//如果输入了正确的用户名和密码,那么必然能查到用户编号,否则结果为空
//登录成功,在管理窗体的状态栏上标示登录的用户名
begin
main.Visible:=true;
main.StatusBar1.Panels[0].Text:=user;
login.Hide;
end
//登录失败,提示用户重新输入
else
begin
ShowMessage('用户名或密码错误,请检查后重新登录');
end
end;
//登录窗口再次显示时,清空原来输入的用户名和密码
procedure Tlogin.FormShow(Sender: TObject);
begin
edit1.Clear;
edit2.Clear;
end;
end.
program JXGL;
uses
Forms,
FormLogin in 'FormLogin.pas' {Form1};
{$R *.res}
begin
Application.Initialize;
Application.Title := '教学管理系统';
Application.CreateForm(Tlogin, login);
Application.Run;
end. 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询