程序编译没问题,运行时出错。
做了一个启动、登录的程序,编译没错,可运行时,当在登录窗口在输入正确的用户名和密码,显示主窗体时,系统提示如下“Access violation at address 004553C6, read of address 000002F4”
工程文件代码如下:
begin
Application.Initialize;
Splashform:=TSplashform.Create(Application);
Splashform.Show;
Splashform.Update;
Sleep(2000);
Splashform.Free;
Dengluform:= TDengluform.Create(Application);
Dengluform.ShowModal;
if Dengluform.ModalResult = 1 then
begin
Application.CreateForm(TMainForm, MainForm);
Dengluform.Free
end;
Application.Run;
end.
登录窗口代码如下:
procedure TDengluform.Button1Click(Sender: TObject);
begin
if Edit1.Text='' then
begin
ShowMessage( '用户名不能为空!');
Edit1.SetFocus;
exit;
end;
if Edit2.Text='' then
begin
ShowMessage( '密码不能为空!');
Edit2.SetFocus;
exit;
end;
loginquery.close;
loginquery.sql.clear;
loginquery.sql.add( 'select * from login where username = '''+edit1.text+ ''' and pass= '''+edit2.text+ '''');
loginquery.open;
if loginquery.RecordCount=0 then
begin
showmessage( '输入的用户名或密码不正确!');
edit1.Clear ;
edit2.Clear ;
end
else
begin
mainform.show;
dengluform.hide;
end;
请教高手!