程序的启动速度太慢?

fj321 2005-04-28 01:53:38
大侠们,我是个初学者,写了一个程序,可启动的速度太慢了,主要是form1要启动二十秒左右,其它几个form都很快,请问该怎么办,下面是我form1的oncreate和onshow事业,请大侠指点:
procedure TForm1.FormCreate(Sender: TObject);
begin
query1.databasename:=extractfiledir(application.exename);
query1.Active:=true;
query2.databasename:=extractfiledir(application.exename);
query2.Active:=true;
query3.databasename:=extractfiledir(application.exename);
query3.Active:=true;
adoquery1.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;'+'Data Source='+extractfiledir(application.exename)+'\record.mdb';
adoquery1.active:=true;
adoquery2.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;'+'Data Source='+extractfiledir(application.exename)+'\record.mdb';
adoquery2.active:=true;
adoquery3.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;'+'Data Source='+extractfiledir(application.exename)+'\record.mdb';
adoquery3.active:=true;

with query3 do
begin
close;
sql.clear;
try
sql.add('select show.xh,show.xm,dwdm.dwmc,show.riqi,show.sksj,show.skcs,show.ljsj from show,dwdm where show.xksj is null and dwdm.dw=show.dw');
open;
label6.Caption:=inttostr(query3.recordcount);
except
sql.clear;
end;
end;

end;



procedure TForm1.FormShow(Sender: TObject);
begin
table1.databasename:=extractfiledir(application.exename);
table1.TableName:='show.db';
table1.Active:=true;


with adoquery1 do
begin
close;
sql.clear;
try
sql.add('select * from 讲座信息 where 日期=:riqi');
adoquery1.Parameters.parambyname('riqi').value:=date;
Open;
except
sql.clear;
end;
if adoquery1.recordcount>=1 then
begin
adoquery1.Last;
cc:=adoquery1.fields[5].value;
label4.Visible:=true;
label4.Caption:=datetostr(date);
label3.Visible:=true;
label3.Caption:=adoquery1.fields[1].value;
label5.Visible:=true;
label5.caption:='主讲人:'+adoquery1.fields[2].value+inttostr(cc);
timer1.Enabled:=true;
end
else begin
timer1.Enabled:=false;
if messagedlg('请先进行讲座信息设定!',mtconfirmation,[mbyes,mbno],0)=mryes then
begin
PostMessage(Handle, WM_SHOWFORM2, 0, 0);
end
else
form1.Close;
end;


end;
end;
...全文
153 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
churchatp1 2005-04-28
  • 打赏
  • 举报
回复
用DataModule吧
把需要连接的信息放到里面,模块也清晰一些,如果可以的话可以少打开几张表,到需要的时候再打开。
lextm 2005-04-28
  • 打赏
  • 举报
回复
另外
1.有一些地方反复调用一个函数也不好
像extractfiledir(application.exename);建议存到一个临时变量好一些.
2.sql.add比较慢,还是设计时就设好SQL属性好一些.

lextm 2005-04-28
  • 打赏
  • 举报
回复
可不可以延迟打开数据库亚,像设个Timer,这么多操作堆在一起肯定是很费时间的.另外用DataModule吧,这么多数据库控件堆在一个窗体里面习惯不好的
yutaocool 2005-04-28
  • 打赏
  • 举报
回复
原因是你在Create和show的时候
连接数据库的操作太多了。

2,497

社区成员

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

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