程序编译没问题,运行时出错。

c19980124 2011-02-23 09:37:59
做了一个启动、登录的程序,编译没错,可运行时,当在登录窗口在输入正确的用户名和密码,显示主窗体时,系统提示如下“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;

请教高手!
...全文
65 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
keeley20 2011-02-23
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 lw19860412 的回复:]

先执行了show,那时还没运行到Application.CreateForm(TMainForm, MainForm);
这句,也就是还没创建呢。
放到前面去
[/Quote]

支持 应该是没Create
lw19860412 2011-02-23
  • 打赏
  • 举报
回复
先执行了show,那时还没运行到Application.CreateForm(TMainForm, MainForm);
这句,也就是还没创建呢。
放到前面去
goodhj 2011-02-23
  • 打赏
  • 举报
回复
begin
Application.Initialize;
Splashform:=TSplashform.Create(Application);
Splashform.Show;
Splashform.Update;
Sleep(2000);
Splashform.Free;
Application.CreateForm(TMainForm, MainForm);
Dengluform:= TDengluform.Create(Application);
Dengluform.ShowModal;
if Dengluform.ModalResult = 1 then
begin
Dengluform.Free
end;
Application.Run;
end.

c19980124 2011-02-23
  • 打赏
  • 举报
回复
问题出现在“mainform.show;”这一步
ok1411 2011-02-23
  • 打赏
  • 举报
回复
单步调试,看哪一行出问题

2,497

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 数据库相关
社区管理员
  • 数据库相关社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧