打印本文 打印本文 关闭窗口 关闭窗口
在Delphi中动态生成QuickReport报表
作者:武汉SEO闵涛  文章来源:敏韬网  点击数2592  更新时间:2009/4/23 18:38:21  文章录入:mintao  责任编辑:mintao
;

    //计算左边界

     if Colum_Num>0 then

       Colum_Data[Colum_Num].Left:=Colum_Data[Colum_Num-1].Left+Colum_Data[Colum_Num-1].Width

     else

        Colum_Data[Colum_Num].Left:=0;

end;

 

procedure DynCreat_TQuery(Inifile_Name:Tinifile);//动态设置TQuery控件的SQL语句

var

    Sql_command:string;

begin

     Flag_CreatQuery:=false;

     Sql_command:=Inifile_Name.Readstring(''''QureyData'''',''''Sql_Command'''','''''''');

     Form_rep.REP_QUERY.Close;

     Form_rep.REP_QUERY.SQL.Clear;

     Form_rep.REP_QUERY.SQL.Append(Sql_command);

     if not Form_rep.REP_QUERY.Prepared then

       Form_rep.REP_QUERY.Prepare;

     try

       Form_rep.REP_QUERY.ExecSQL;

       Form_rep.REP_QUERY.Active:=true;

       Form_rep.REP_QUERY.AutoCalcFields:=true;

       Flag_CreatQuery:=true;

     except

       Application.MessageBox(''''SQL语句错误!'''',''''系统提示'''',MB_ICONWARNING);

       Flag_CreatQuery:=false;

     end;

end;

 

procedure Form_rep_init();

var  i_count:integer;

     Rep_IniFile:Tinifile;//打开的INI文件名

     Col_Height:integer;

     Flag_Sum:boolean;

begin

   Rep_IniFile:=Open_IniFile);//打开临时文件文件

   Read_Rep_Summary(Rep_IniFile);//读取报表的摘要信息

   Read_Col_Summary(Rep_IniFile);//读取报表列的摘要信息

   //根据读取的报表的各项参数,动态创建报表控件

   with   Form_rep  do

   begin

      Flag_CreatTQRExpr:=false;//表示现在还没有创建TQRExpr控件

      DynCreat_TQuery(Rep_IniFile);

         if  Flag_CreatQuery then

            begin

             QRLabel_title.Caption:=rep_Summary.Title;

             QRLabel_Header.Caption:=rep_Summary.Title;

             //设置页面信息

             QuickRep.Page.Orientation:=rep_Summary.Orientation;

             QuickRep.Page.PaperSize:=rep_Summary.Page;

             SetLength(Colum_Data,rep_Summary.Columns);

             SetLength(Colum_Name,rep_Summary.Columns);

             for  i_count:=0 to rep_Summary.Columns-1 do

               begin

                  DynCreat_TQRRichtext(i_count);//动态创建TQRRichtext控件

                                 DynCreat_TQRDBRichText(i_count,Col_Height,Form_rep.REP_QUERY)//动态创建TQRDBText控件

               end;

              //关闭rep_x.ini文件

              Rep_IniFile.Destroy();

            end

          else

             Form_rep.Close;

    end;

end;

 

procedure TForm_rep.QuickRepAfterPreview(Sender: TObject);//浏览完毕,释放所有创建的组件

var i_count:integer;

begin

  for i_count:=0 to rep_Summary.Columns-1 do

   begin                         ;

     Colum_Name[i_count].free;

     Colum_Data[i_count].free;

   end;

end;

end.

 

三、需要注意的问题

----QuickReport中绘制表格线,除了文中提到的方法外,还可以使用QRShape控件。但不管使用那种方法,都要仔细计算,要根据打印的效果反复调整,才能保证表格线不产生偏差。

----所有动态创建的控件使用过后,一定要释放掉。

----临时文件在使用过后,也要清空。

 

----上文所示程序仅仅是笔者为了说明思路而简化的例程。在笔者实际的应用中,所有用到的控件(包括表单Form),都是动态生成的。而且在生成报表时,还可以动态生成统计信息,插入图表等,有兴趣的朋友可以发信到 chief_marshal@sina.com 和我一起讨论细节。

上一页  [1] [2] [3] 

打印本文 打印本文 关闭窗口 关闭窗口