起步软件技术论坛-X3

 找回密码
 立即注册
搜索
查看: 146|回复: 4

【搞定】报错:“对象必须在环境释放之前释放”的问题**

[复制链接]
发表于 2007-10-15 14:48:09 | 显示全部楼层 |阅读模式
我做了一个报表向导的窗口,打开不同的报表窗口。当打开一个报表(预览状态)关闭后,再关闭报表向导窗口时,就报错:“对象必须在环境释放之前释放”!下面是报表向导窗口的代码,请问到底是哪个对象没有释放掉啊????

unit BBXDCT;
interface
uses
  Business.System, Business.Forms, Business.System.SysUtils, GGHS, Business.Data, Business.Model;

type
  TBBXDCT = class(TForm)
    Shape1: TShape;
    GroupBox2: TGroupBox;
    dtpTJSJ: TDateTimePicker;
    Label1: TLabel;
    Label2: TLabel;
    RadioButton1: TRadioButton;
    RadioButton2: TRadioButton;
    RadioButton3: TRadioButton;
    btnNext: TButton;
    btnCancel: TButton;
    InfoBroker1: TInfoBroker;
    DataSetBroker1: TDataSetBroker;
    DataSetBroker2: TDataSetBroker;
    DataSetBroker3: TDataSetBroker;
    RadioButton4: TRadioButton;
    RadioButton5: TRadioButton;
    DataSetBroker4: TDataSetBroker;
    DataSetBroker5: TDataSetBroker;
    procedure btnNextClick(Sender: TObject);
    procedure btnExportClick(Sender: TObject);
  private
    {private declarations}
  public
    {public declarations}
  end;

implementation

procedure TBBXDCT.btnNextClick(Sender: TObject);
var a: TBBSJCKFZYGJBCT;
var aa: TGBFSPTJHZCT;
var aaa: TSPFGBTJHZCT;
var ab: TMYFSHZB;
var abb: TMYFSFSPTJHZB;

var y: string;
var m: string;
var d: string;
var i: Integer;
var strSql: string;
begin
  DateTimeToString(y, 'yyyy', dtpTJSJ.Date);
  DateTimeToString(m, 'm', dtpTJSJ.Date);
  DateTimeToString(d, 'd', dtpTJSJ.Date);

  if(RadioButton1.Checked) then
  begin
  strSql := 'select a.国家地区,a.地区,a.累计金额, '
         +'Round(a.累计金额/(select sum(FP.USD) from FP where Year(FP.IDate)='+y+' and Month(FP.IDate)<='+m+')*1000000,2) as 占总额, '
         +'ISNULL(b.上年同期,0) as 上年同期, '
         +'case when IsNull(b.上年同期,0)=0 then null else '
         +'Round((a.累计金额-b.上年同期)/b.上年同期,2)  end as 同比增长 '
         +'from ( '
         +'select COUNTRYCODE.NAME AS 国家地区,(select a.Name from CountryCode a where code=substring(COUNTRYCODE.code,1,3)) AS 地区, '
         +'sum(FP.USD)/10000 as 累计金额 '
         +'FROM FP, COUNTRYCODE '
         +'WHERE '
         +'FP.CountryId = COUNTRYCODE.CODE and COUNTRYCODE.CODELEVEL = 3 '
         +'and COUNTRYCODE.OVERSEAS = 1 and FP.INVICETYPE <> ''投标业务'' and FP.INVICETYPE <> ''国内贸易'' '
         +'and FP.INVICETYPE <> ''招标业务'' and FP.EMPLOYEEID is not null and FP.EMPLOYEEID <> '''' '
         +'and (Year(FP.IDate)='+y+' and Month(FP.IDate)<='+m+' ) '
         +'GROUP BY COUNTRYCODE.NAME,COUNTRYCODE.AREA,COUNTRYCODE.CODE,YEAR(FP.IDATE) '
         +') a '
         +'left join '
         +'( '
         +'select COUNTRYCODE.NAME AS 国家地区,(select a.Name from CountryCode a where code=substring(COUNTRYCODE.code,1,3)) AS 地区, '
         +'sum(FP.USD)/10000 as 上年同期 '
         +'FROM FP, COUNTRYCODE '
         +'WHERE '
         +'FP.CountryId = COUNTRYCODE.CODE and COUNTRYCODE.CODELEVEL = 3 '
         +'and COUNTRYCODE.OVERSEAS = 1 and FP.INVICETYPE <> ''投标业务'' and FP.INVICETYPE <> ''国内贸易'' '
         +'and FP.INVICETYPE <> ''招标业务'' and FP.EMPLOYEEID is not null and FP.EMPLOYEEID <> '''' '
         +'and (Year(FP.IDATE)= '+IntToStr(StrToInt(y)-1)+' and Month(FP.IDate)<='+m+' ) '
         //and ()
         +'GROUP BY COUNTRYCODE.NAME,COUNTRYCODE.AREA,COUNTRYCODE.CODE,YEAR(FP.IDATE) '
         +') b '
         +'on a.国家地区=b.国家地区 '
         +'order by a.地区,a.国家地区 ASC ';
  TSQLDataSet(DataSetBroker1.DataSet).Close;
  TSQLDataSet(DataSetBroker1.DataSet).SQL.Text := strSql;
  TSQLDataSet(DataSetBroker1.DataSet).Open;
  a := TBBSJCKFZYGJBCT.Create(Context);
  a.Show;
  end
  else if(RadioButton2.Checked) then
  begin
    strSql := 'select ltrim(HT.CountryID) as 贸易国码, ltrim(CountryCode.Name) as 贸易国别,ltrim(HT.CIQId) as 海关代码, ltrim(GOODSCODE.NAME) as 商品名称 ,sum(HT.USD)/10000 as 累计金额 '
              +' from HT,GOODSCODE,CountryCode '
              +' where HT.INPUTDATE<='''+y+'-'+m+'-'+d+''' and HT.CIQId=GOODSCODE.CODE and CountryCode.Code=HT.CountryId '
              +' group by HT.COUNTRYID,CountryCode.Name,HT.CIQId,GOODSCODE.NAME';
    TSQLDataSet(DataSetBroker2.DataSet).Close;
    TSQLDataSet(DataSetBroker2.DataSet).SQL.Text := strSql;
    TSQLDataSet(DataSetBroker2.DataSet).Open;
    aa := TGBFSPTJHZCT.Create(Context);
    aa.Show;
  end
  else if(RadioButton3.Checked) then
  begin
    strSql := 'select lTrim(HT.CountryID) as 贸易国码,lTrim(CountryCode.Name) as 贸易国别,lTrim(HT.CIQId) as 海关代码,'
              +' lTrim(GOODSCODE.NAME) as 商品名称 ,sum(HT.USD)/10000 as 累计金额 '
              +' from HT,GOODSCODE,CountryCode '
              +' where HT.INPUTDATE<='''+y+'-'+m+'-'+d+''' and HT.CIQId=GOODSCODE.CODE and CountryCode.Code=HT.CountryId '
              +' group by HT.CIQId,GOODSCODE.NAME, HT.CountryID,CountryCode.Name';
    TSQLDataSet(DataSetBroker3.DataSet).Close;
    TSQLDataSet(DataSetBroker3.DataSet).SQL.Text := strSql;
    TSQLDataSet(DataSetBroker3.DataSet).Open;
    aaa := TSPFGBTJHZCT.Create(Context);
    aaa.Show;
  end
  else if(RadioButton4.Checked) then
  begin
    strSql := 'select lTrim(a.贸易方式) as 贸易方式,lTrim(a.累计金额) as 累计金额,ISNULL(b.上年同期,0) as 上年同期, Round(a.累计金额*1000000/(select sum(USD) from HT'
              +' where Year(InputDate)='+y+'),2) as 占总额 '
              +' from (select TradeKindID as 贸易方式,sum(USD)/10000 as 累计金额 from HT where year(InputDate)='+y+' and month(InputDate)<'+m+' group by TradeKindID) a left join '
              +' (select TradeKindID as 贸易方式, sum(USD)/10000 as 上年同期 from HT where year(InputDate)='+IntToStr(StrToInt(y)-1)+' and month(InputDate)<'+m+' group by '
              +' TradeKindID) b '
              +' on a.贸易方式=b.贸易方式';
    TSQLDataSet(DataSetBroker4.DataSet).Close;
    TSQLDataSet(DataSetBroker4.DataSet).SQL.Text := strSql;
    TSQLDataSet(DataSetBroker4.DataSet).Open;
    ab := TMYFSHZB.Create(Context);
    ab.Show;
  end
  else if(RadioButton5.Checked) then
  begin
    strSql := 'select lTrim(HT.TradeKindId) as 贸易方式,lTrim(HT.CIQId) as 海关代码,lTrim(GoodsCode.Name) as 商品名称,sum(HT.USD)/10000 as 累计金额 '
              +' from HT,GoodsCode '
              +' where year(HT.InputDate)='+y+' and month(HT.InputDate)<'+m+' and HT.CIQId=GoodsCode.Code '
              +' group by HT.TradeKindId,HT.CIQId,GoodsCode.Name';

    TSQLDataSet(DataSetBroker5.DataSet).Close;
    TSQLDataSet(DataSetBroker5.DataSet).SQL.Text := strSql;
    TSQLDataSet(DataSetBroker5.DataSet).Open;
    abb := TMYFSFSPTJHZB.Create(Context);
    abb.Show;
  end;
end;


end.
回复

使用道具 举报

发表于 2007-10-15 14:56:06 | 显示全部楼层
类似这样的代码,你在哪里释放对象的呢?
    abb := TMYFSFSPTJHZB.Create(Context);
    abb.Show;
回复 支持 反对

使用道具 举报

 楼主| 发表于 2007-10-15 16:26:06 | 显示全部楼层
在关闭报表(预览窗体)时释放该窗体对象,或者在关闭向导窗体的时候释放窗体对象都可以,我在窗体的OnClose事件中写了释放代码,可是运行出现下图错误:

未命名.jpg

14.59 KB, 下载次数: 107

回复 支持 反对

使用道具 举报

发表于 2007-10-15 17:16:13 | 显示全部楼层
运行前,编译,签入
回复 支持 反对

使用道具 举报

 楼主| 发表于 2007-10-17 09:40:41 | 显示全部楼层
好的,解决
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Justep Inc.

GMT+8, 2025-6-28 19:02 , Processed in 0.043472 second(s), 18 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表