打开一个窗口竟要5秒钟,怎么优化?(100分)

  • 主题发起人 lingmao3
  • 开始时间
L

lingmao3

Unregistered / Unconfirmed
GUEST, unregistred user!
我数据库用的是局域网sqlserver,我将这段代码放在oncreate,onshow,也是五秒,<br>求高人指点:<br>我还放了一个dbgrid和adoquery2相连.<br><br>procedure Tformxjuser.FormActivate(Sender: TObject);<br>&nbsp; var vvi:integer; IniFile : TIniFile;<br>begin<br>&nbsp; TabSheet1.Enabled:=false;<br>&nbsp; BitBtn12.Enabled:=true;<br>&nbsp; BitBtn13.Enabled:=true;<br>&nbsp; BitBtn14.Enabled:=true;<br>&nbsp; BitBtn3.Enabled:=true;<br>&nbsp; BitBtn2.Visible:=false;<br>&nbsp; BitBtn1.Visible:=false;<br>&nbsp; BitBtn15.Visible:=false;<br>&nbsp; CheckBox2.checked:=true;//列表选项<br>&nbsp; CheckBox3.checked:=false;//个性化设置<br>&nbsp; Panel1.Visible:=true;//列表选项<br>&nbsp; Panel4.Visible:=false;//个性化设置<br>&nbsp; paneltb.Visible:=false; //自动填表<br>&nbsp; formini;<br>&nbsp; &nbsp;adoquery2.Close;<br>&nbsp;adoquery2.SQL.Clear;<br>&nbsp;adoquery2.SQL.add('select * from t_xjuser where '+trim(editwhere.text));<br>&nbsp;//adoquery1.Close;<br>&nbsp;//adoquery1.SQL.Clear;<br>&nbsp;//adoquery1.SQL.add('select * from t_xjuser where '+trim(editwhere.text));<br>&nbsp;//adoquery2.active:=true;<br>&nbsp;//adoquery1.active:=true;<br>&nbsp;if trim(editwheretemp.text)&lt;&gt;'' then &nbsp;{被其它窗口关联}<br>&nbsp;begin<br>&nbsp; &nbsp;adoquery2.Close;<br>&nbsp; &nbsp;adoquery2.SQL.Clear;<br>&nbsp; &nbsp;adoquery2.SQL.add('select * from t_xjuser where '+trim(editwhere.text)+trim(editwheretemp.text));<br>&nbsp;end; {被其它窗口关联}<br>&nbsp;try &nbsp; &nbsp;{//2}<br>&nbsp; adoquery2.Open;<br>&nbsp;Except<br>&nbsp; ShowMessage('查询出错,请与管理员联系!');<br>&nbsp; Exit;<br>&nbsp;end; &nbsp; {//2 }<br>&nbsp;if adoquery2.RecordCount&lt;1 then showmessage('没有查询记录,请点击“查询”按钮再进行查询');<br><br>&nbsp;for vvi:=0 to dbgrid1.Columns.Count-1 do//多字段排序<br>&nbsp;begin //1<br>&nbsp; &nbsp;ComboBoxpx1.items.add(dbgrid1.Columns[vvi].fieldname);<br>&nbsp; &nbsp;ComboBoxpx3.items.add(dbgrid1.Columns[vvi].fieldname);<br>&nbsp; &nbsp;ComboBoxpx5.items.add(dbgrid1.Columns[vvi].fieldname);<br>&nbsp;end; &nbsp;//1 &nbsp; 多字段排序<br>&nbsp;adoquery2Open;//查询更新后的操作。<br><br>&nbsp;if fileexists('self/用户管理-列表栏头.ini') then<br>&nbsp;begin //2<br>&nbsp;iniFile := TIniFile.Create('self/用户管理-列表栏头.ini');<br>&nbsp;for vvi:=0 to dbgrid1.Columns.Count-1 do<br>&nbsp;begin //1<br>&nbsp; &nbsp;dbgrid1.Columns[vvi].width:=strtoint(IniFile.ReadString('列表', 'width'+inttostr(vvi)+'', ''));<br>&nbsp; &nbsp;dbgrid1.Columns[vvi].fieldname:=IniFile.ReadString('列表', 'fieldname'+inttostr(vvi)+'', '');<br>&nbsp; &nbsp;dbgrid1.Columns[vvi].title.Caption:=IniFile.ReadString('列表', 'caption'+inttostr(vvi)+'', '');<br>&nbsp;end; &nbsp;//1<br>&nbsp;IniFile.Free;<br>&nbsp;end;//2<br>&nbsp;BitBtndgsxClick(Sender);//定格刷新<br>end; //fromactive结束
 
可能是连数据库的时间慢。找找这方面的原因吧。
 
肯定是连数据库的时间慢,可怎么解决?<br>字段就五个,
 
试试把*换成字段名,另外那张表里有多少条记录?
 
开窗口时,先后顺序是:<br>oncreat<br>onshow<br>onActivate被调2次[:(]<br>我改过来了.<br>将程序放在onshow里就OK了.<br>谢谢大家
 
顶部