关闭指定窗口时报错(50分)

  • 主题发起人 主题发起人 jackson_wu
  • 开始时间 开始时间
J

jackson_wu

Unregistered / Unconfirmed
GUEST, unregistred user!
小兄自己写了一个小程序,目的是实现一些查询<br> &nbsp; 主菜单中有4个button,当单击一个button时打开一个画面(From1),然后再单击[查询]显示另一个画面(From2),输入相应的条件,然后再单击确定,执行相应的语句并关闭窗口From2,关闭From1时再将数据集关闭<br><br> &nbsp; 存在的问题是:当我关闭FrmCwGCZK后,再关闭[主菜单]时总报:标题:Application Error &nbsp;内容:Exception EAccessViolation in module WBL.exe at 0009d4A4 Access violation at address 0049D4A4 in module wbl.exe Write of address 00E46700,单击确定后,标题:Debugger Exception Notification 内容:Project Wbl.exe raised exception class EAccessViolation with message 'Access violation at address 00406022 in module' wbl.exe'.Read of address 01062DF8'.Process stopped.Use Step or Run to Continue<br> &nbsp; 如果打开FrmCwGCZK后,不执行sql就关闭FrmCwGCZK,然后再关闭[主菜单],不会报错;<br> &nbsp; 如果打开FrmCwGCZK后,执行了sql后,再关闭FrmCwGCZK,回到[主菜单]后,再打开另一个窗口,执行另一个查询后关闭,再关闭[主菜单]不会报错。<br> &nbsp; 如果打开其它From后,执行sql后关闭,再关闭[主菜单]不会报错.<br><br> &nbsp; 这个问题困扰我好几天了,帮帮我吧!!!<br><br><br>代码如下:<br>unit CwGCZKSelect;<br>interface<br>uses<br> &nbsp;Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> &nbsp;Dialogs, StdCtrls, ComCtrls, DB, ADODB;<br><br>type<br> &nbsp;TFrmCwGCZKSelect = class(TForm)<br> &nbsp; &nbsp;Label1: TLabel;<br> &nbsp; &nbsp;Label2: TLabel;<br> &nbsp; &nbsp;DateTimePicker1: TDateTimePicker;<br> &nbsp; &nbsp;ComboBox1: TComboBox;<br> &nbsp; &nbsp;Button1: TButton;<br> &nbsp; &nbsp;Button2: TButton;<br> &nbsp; &nbsp;ADOQuery1: TADOQuery;<br> &nbsp; &nbsp;procedure Button1Click(Sender: TObject);<br> &nbsp; &nbsp;procedure Button2Click(Sender: TObject);<br> &nbsp;private<br> &nbsp; &nbsp;{ Private declarations }<br> &nbsp;public<br> &nbsp; &nbsp;{ Public declarations }<br> &nbsp;end;<br><br>var<br> &nbsp;FrmCwGCZKSelect: TFrmCwGCZKSelect;<br><br>implementation<br><br>uses CwGCZK;<br><br>{$R *.dfm}<br><br>procedure TFrmCwGCZKSelect.Button1Click(Sender: TObject);<br>begin<br> &nbsp;with self.ADOQuery1 do<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp;ADOQuery1.Close;<br> &nbsp; &nbsp; &nbsp;ADOQuery1.SQL.Clear;<br> &nbsp; &nbsp; &nbsp;ADOQuery1.SQL.Add('select a.porder,a.hcode,c.name,e.klotvalue,f.bumo,d.bunr,a.ocnt,a.proc_no '<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;+' &nbsp;from ( SELECT a.Proc_no,a.INDATE,A.PORDER,A.HCODE,A.OCNT FROM sks.dbo.hs_proc a , '<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;+' (select porder,max(KBAN) KBAN from &nbsp;sks.dbo.hs_proc where indate &lt;=:EndDate and '<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;+' porder not in ( select distinct porder from (select * from &nbsp;sks.dbo.hs_proc where indate &lt;=:EndDate1) a '<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;+' where (KBAN = '+''''+'999'+''''+' and class = '+''''+'j'+''''+')) group by porder ) B '<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;+' WHERE A.PORDER=B.PORDER AND A.KBAN=B.KBAN AND PKUBUN ='+''''+'T'+''''+' &nbsp;) A &nbsp;'<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;+' LEFT JOIN tpics31.dbo.xhead c on a.hcode=c.code &nbsp;'<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;+' Left Join Tpics31.dbo.xitem d on a.hcode=d.code &nbsp; '<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;+' Left Join sks.dbo.hs_procl e on A.PORDER=e.kporder and e.klotcode='+''''+'9998'+''''<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;+' Left Join tpics31.dbo.xslip f on a.PORDER =f.PORDER and a.hcode=f.code &nbsp;'<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;+' WHERE &nbsp;c.mainbumo=d.bumo AND d.BUNR like :strbunr '<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;+' ORDER BY A.PORDER ');<br> &nbsp; &nbsp; &nbsp;ADOQuery1.Parameters.ParamByName('strbunr').DataType:=ftString;<br> &nbsp; &nbsp; &nbsp;ADOQuery1.Parameters.ParamByName('strbunr').Value:=Trim(Self.ComboBox1.Text)+'%';<br> &nbsp; &nbsp; &nbsp;ADOQuery1.Parameters.ParamByName('EndDate').DataType:=ftString;<br> &nbsp; &nbsp; &nbsp;ADOQuery1.Parameters.ParamByName('EndDate').Value:=FormatDatetime('yyyymmdd',DateTimePicker1.Date)+'1';<br> &nbsp; &nbsp; &nbsp;ADOQuery1.Parameters.ParamByName('EndDate1').DataType:=ftString;<br> &nbsp; &nbsp; &nbsp;ADOQuery1.Parameters.ParamByName('EndDate1').Value:=FormatDatetime('yyyymmdd',DateTimePicker1.Date)+'1';<br> &nbsp; &nbsp; &nbsp;try<br> &nbsp; &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;self.ADOQuery1.open;<br> &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp;except<br> &nbsp; &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;showmessage('连接数据库失败!!!!') &nbsp;;<br> &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp;self.ComboBox1.Text:='';<br> &nbsp; &nbsp; &nbsp;FrmCwGCZKSelect.Close;<br> &nbsp; &nbsp;end;<br>end;<br><br>procedure TFrmCwGCZKSelect.Button2Click(Sender: TObject);<br>begin<br> &nbsp;FrmCwGCZKSelect.Close;<br>end;<br>end.<br><br><br><br>unit CwGCZK;<br><br>interface<br><br>uses<br> &nbsp;Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> &nbsp;Dialogs, StdCtrls, DB, GridsEh, DBGridEh, ComCtrls,comobj;<br><br>type<br> &nbsp;TFrmCwGCZK = class(TForm)<br> &nbsp; &nbsp;Button1: TButton;<br> &nbsp; &nbsp;DataSource1: TDataSource;<br> &nbsp; &nbsp;DBGridEh1: TDBGridEh;<br> &nbsp; &nbsp;Button2: TButton;<br> &nbsp; &nbsp;procedure Button1Click(Sender: TObject);<br> &nbsp; &nbsp;procedure FormClose(Sender: TObject; var Action: TCloseAction);<br> &nbsp; &nbsp;procedure FormCreate(Sender: TObject);<br> &nbsp;private<br> &nbsp; &nbsp;{ Private declarations }<br> &nbsp;public<br> &nbsp; &nbsp;{ Public declarations }<br> &nbsp;end;<br><br>var<br> &nbsp;FrmCwGCZK: TFrmCwGCZK;<br><br>implementation<br><br>uses CwGCZKSelect;<br><br>{$R *.dfm}<br><br>procedure TFrmCwGCZK.Button1Click(Sender: TObject);<br>begin<br> &nbsp;FrmCwGCZKSelect.ShowModal;<br>end;<br><br><br>procedure TFrmCwGCZK.FormClose(Sender: TObject; var Action: TCloseAction);<br>begin<br> &nbsp;FrmCwGCZKSelect.ADOQuery1.close;<br>end;<br><br>procedure TFrmCwGCZK.FormCreate(Sender: TObject);<br>begin<br> &nbsp;FrmCwGCZK.DBGridEh1.Columns[0].Width:=90;<br> &nbsp;FrmCwGCZK.DBGridEh1.Columns[1].Width:=90;<br> &nbsp;FrmCwGCZK.DBGridEh1.Columns[2].Width:=120;<br> &nbsp;FrmCwGCZK.DBGridEh1.Columns[3].Width:=120;<br> &nbsp;FrmCwGCZK.DBGridEh1.Columns[4].Width:=40;<br> &nbsp;FrmCwGCZK.DBGridEh1.Columns[5].Width:=60;<br> &nbsp;FrmCwGCZK.DBGridEh1.Columns[6].Width:=60;<br> &nbsp;FrmCwGCZK.DBGridEh1.Columns[7].Width:=40;<br>end;<br>end.
 
你在第一个窗体关闭的时候FrmCwGCZKSelect.ADOQuery1.close了一次,第二个窗体关闭的时候又关闭了一次.<br><br>主要是第二此关闭的时候,第一个船体已经释放了,所以找不到这个query
 
我觉得你可以这样测试。<br>你把FrmCwGCZKSelect中的ADOQuery1放置在FrmCwGCZK窗口中,给我的感觉你的查询数据是在FrmCwGCZK窗口显示的。你可以试试看,
 
hityou:<br>你说的是:在Button1事件中FrmCwGCZKSelect.Close;这句吗?<br>FrmCwGCZKSelect.ADOQuery1.close这一句我是写在另一个窗体的关闭时的事件中,如果不这样写的话第一次打开FrmCwGCZK后,查询出数据后,再关闭,再次打开时就会打开前一次的数据集。<br><br>再帮我看看吧
 
写的太乱了。
 
你是指程序还是指对问题的说明
 
你把这些都在弹出的窗体里面处理.动态创建,动态销毁.<br>不要放在外面就成了.
 
hityou<br>可不可以稍微具体一点
 

Similar threads

后退
顶部