delphi 登陆界面后显示主窗体,出现 access violation 错误
delphi先是登陆窗体,用户名密码正确后显示主窗体,程序如下,目前错误,登陆界面运行后,出现access violation at address错误,求解哪错了。。。哎,憋了我2天了。。那是相当难受unit Unit20141126_2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, ADODB;
type
TForm2 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
uses Unit20141126_2_2;
{$R *.dfm}
procedure TForm2.Button1Click(Sender: TObject);
var
name,password,sqlstr:string;
begin
if (length(trim(edit1.Text))>0) or (length(trim(edit2.Text))>0) then
begin
name:=trim(edit1.Text); //取得用户输入的用户名
password:=trim(edit2.Text); //取得用户输入的密码
sqlstr:='select * from t_user where (username='''+name+''') and(userpass='''+password+''')';
with Tadoquery.create(nil) do
try
connection:=form1.adoconnection1;
close;
sql.clear;
sql.add(sqlstr);
open;
if recordcount>0 then
begin
form2.hide;
showmessage('登陆成功');
Application.createForm(TForm1,Form1);
Form1.ShowModal;
end
else
begin
showmessage('用户名密码错误');
edit1.SetFocus;
edit1.SelectAll;
end;
finally
free;
end;
end
else
begin
showmessage('请输入用户名密码');
edit1.SelectAll;
end;
end;
procedure TForm2.Button2Click(Sender: TObject);
begin
close;
end;
end.