J
jackson_wu
Unregistered / Unconfirmed
GUEST, unregistred user!
小兄自己写了一个小程序,目的是实现一些查询<br> 主菜单中有4个button,当单击一个button时打开一个画面(From1),然后再单击[查询]显示另一个画面(From2),输入相应的条件,然后再单击确定,执行相应的语句并关闭窗口From2,关闭From1时再将数据集关闭<br><br> 存在的问题是:当我关闭FrmCwGCZK后,再关闭[主菜单]时总报:标题:Application Error 内容: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> 如果打开FrmCwGCZK后,不执行sql就关闭FrmCwGCZK,然后再关闭[主菜单],不会报错;<br> 如果打开FrmCwGCZK后,执行了sql后,再关闭FrmCwGCZK,回到[主菜单]后,再打开另一个窗口,执行另一个查询后关闭,再关闭[主菜单]不会报错。<br> 如果打开其它From后,执行sql后关闭,再关闭[主菜单]不会报错.<br><br> 这个问题困扰我好几天了,帮帮我吧!!!<br><br><br>代码如下:<br>unit CwGCZKSelect;<br>interface<br>uses<br> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> Dialogs, StdCtrls, ComCtrls, DB, ADODB;<br><br>type<br> TFrmCwGCZKSelect = class(TForm)<br> Label1: TLabel;<br> Label2: TLabel;<br> DateTimePicker1: TDateTimePicker;<br> ComboBox1: TComboBox;<br> Button1: TButton;<br> Button2: TButton;<br> ADOQuery1: TADOQuery;<br> procedure Button1Click(Sender: TObject);<br> procedure Button2Click(Sender: TObject);<br> private<br> { Private declarations }<br> public<br> { Public declarations }<br> end;<br><br>var<br> FrmCwGCZKSelect: TFrmCwGCZKSelect;<br><br>implementation<br><br>uses CwGCZK;<br><br>{$R *.dfm}<br><br>procedure TFrmCwGCZKSelect.Button1Click(Sender: TObject);<br>begin<br> with self.ADOQuery1 do<br> begin<br> ADOQuery1.Close;<br> ADOQuery1.SQL.Clear;<br> ADOQuery1.SQL.Add('select a.porder,a.hcode,c.name,e.klotvalue,f.bumo,d.bunr,a.ocnt,a.proc_no '<br> +' from ( SELECT a.Proc_no,a.INDATE,A.PORDER,A.HCODE,A.OCNT FROM sks.dbo.hs_proc a , '<br> +' (select porder,max(KBAN) KBAN from sks.dbo.hs_proc where indate <=:EndDate and '<br> +' porder not in ( select distinct porder from (select * from sks.dbo.hs_proc where indate <=:EndDate1) a '<br> +' where (KBAN = '+''''+'999'+''''+' and class = '+''''+'j'+''''+')) group by porder ) B '<br> +' WHERE A.PORDER=B.PORDER AND A.KBAN=B.KBAN AND PKUBUN ='+''''+'T'+''''+'   A '<br> +' LEFT JOIN tpics31.dbo.xhead c on a.hcode=c.code '<br> +' Left Join Tpics31.dbo.xitem d on a.hcode=d.code '<br> +' Left Join sks.dbo.hs_procl e on A.PORDER=e.kporder and e.klotcode='+''''+'9998'+''''<br> +' Left Join tpics31.dbo.xslip f on a.PORDER =f.PORDER and a.hcode=f.code '<br> +' WHERE c.mainbumo=d.bumo AND d.BUNR like :strbunr '<br> +' ORDER BY A.PORDER ');<br> ADOQuery1.Parameters.ParamByName('strbunr').DataType:=ftString;<br> ADOQuery1.Parameters.ParamByName('strbunr').Value:=Trim(Self.ComboBox1.Text)+'%';<br> ADOQuery1.Parameters.ParamByName('EndDate').DataType:=ftString;<br> ADOQuery1.Parameters.ParamByName('EndDate').Value:=FormatDatetime('yyyymmdd',DateTimePicker1.Date)+'1';<br> ADOQuery1.Parameters.ParamByName('EndDate1').DataType:=ftString;<br> ADOQuery1.Parameters.ParamByName('EndDate1').Value:=FormatDatetime('yyyymmdd',DateTimePicker1.Date)+'1';<br> try<br> begin<br> self.ADOQuery1.open;<br> end;<br> except<br> begin<br> showmessage('连接数据库失败!!!!') ;<br> end;<br> end;<br> self.ComboBox1.Text:='';<br> FrmCwGCZKSelect.Close;<br> end;<br>end;<br><br>procedure TFrmCwGCZKSelect.Button2Click(Sender: TObject);<br>begin<br> FrmCwGCZKSelect.Close;<br>end;<br>end.<br><br><br><br>unit CwGCZK;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> Dialogs, StdCtrls, DB, GridsEh, DBGridEh, ComCtrls,comobj;<br><br>type<br> TFrmCwGCZK = class(TForm)<br> Button1: TButton;<br> DataSource1: TDataSource;<br> DBGridEh1: TDBGridEh;<br> Button2: TButton;<br> procedure Button1Click(Sender: TObject);<br> procedure FormClose(Sender: TObject; var Action: TCloseAction);<br> procedure FormCreate(Sender: TObject);<br> private<br> { Private declarations }<br> public<br> { Public declarations }<br> end;<br><br>var<br> FrmCwGCZK: TFrmCwGCZK;<br><br>implementation<br><br>uses CwGCZKSelect;<br><br>{$R *.dfm}<br><br>procedure TFrmCwGCZK.Button1Click(Sender: TObject);<br>begin<br> FrmCwGCZKSelect.ShowModal;<br>end;<br><br><br>procedure TFrmCwGCZK.FormClose(Sender: TObject; var Action: TCloseAction);<br>begin<br> FrmCwGCZKSelect.ADOQuery1.close;<br>end;<br><br>procedure TFrmCwGCZK.FormCreate(Sender: TObject);<br>begin<br> FrmCwGCZK.DBGridEh1.Columns[0].Width:=90;<br> FrmCwGCZK.DBGridEh1.Columns[1].Width:=90;<br> FrmCwGCZK.DBGridEh1.Columns[2].Width:=120;<br> FrmCwGCZK.DBGridEh1.Columns[3].Width:=120;<br> FrmCwGCZK.DBGridEh1.Columns[4].Width:=40;<br> FrmCwGCZK.DBGridEh1.Columns[5].Width:=60;<br> FrmCwGCZK.DBGridEh1.Columns[6].Width:=60;<br> FrmCwGCZK.DBGridEh1.Columns[7].Width:=40;<br>end;<br>end.