转至繁体中文版     | 网站首页 | 图文教程 | 资源下载 | 站长博客 | 图片素材 | 武汉seo | 武汉网站优化 | 
最新公告:     敏韬网|教学资源学习资料永久免费分享站!  [mintao  2008年9月2日]        
您现在的位置: 学习笔记 >> 图文教程 >> 软件开发 >> Delphi程序 >> 正文
Delphi程序执行时实时生成报表         ★★★★

Delphi程序执行时实时生成报表

作者:闵涛 文章来源:闵涛的学习笔记 点击数:3046 更新时间:2009/4/23 18:42:10
;       CHBNAME[I].Alignment:=taCenter;
        CHBNAME[I].Caption:=Query.Fields[I].DisplayName;//取字段作为列名
        CHBNAME[I].BringToFront;

        DBShape[I]:=TQRShape.Create(DB); //建立细节带区线条控件
        DBShape[I].Parent:=DB;
        DBShape[I].Top:=-1;
        DBShape[I].Left:=CHBlf;
        DBShape[I].Width:=ObWidth+1;
        DBShape[I].Height:=17;

        DBNAME[I]:=TQRDBText.Create(DB); //建立细节带区控件
        DBNAME[I].Parent:=DB;
        DBNAME[I].ParentReport:=QuickRep;
        DBNAME[I].Top:=2;
        DBNAME[I].Left:=CHBlf+2;
        DBNAME[I].AutoSize:=False;
        DBNAME[I].Width:=ObWidth-3;
        DBNAME[I].Height:=13;
        DBNAME[I].Alignment:=Dj;
        DBNAME[I].DataSet:=Query;
        DBNAME[I].DataField:=Query.Fields[I].FieldName;
        DBNAME[I].BringToFront;

        if Tj1.Checked then begin  //是否建立页脚带区?
          FBShape[I]:=TQRShape.Create(FB); //建立页脚带区线条控件
          FBShape[I].Parent:=FB;
          FBShape[I].Top:=0;
          FBShape[I].Left:=CHBlf;
          FBShape[I].Width:=ObWidth+1;
          FBShape[I].Height:=17;

          if (Query.Fields[I].DataType=ftFloat) or
             (Query.Fields[I].DataType=ftCurrency) or (I<2) then
          begin //如果字段类型为数值类型则建立
            FBNAME[I]:=TQRExpr.Create(FB); //建立页脚带区控件
            FBNAME[I].Parent:=FB;
            FBNAME[I].ParentReport:=QuickRep;
            FBNAME[I].Top:=3;
            FBNAME[I].Left:=CHBlf+2;
            FBNAME[I].AutoSize:=False;
            FBNAME[I].Width:=ObWidth-3;
            FBNAME[I].Height:=13;
            FBNAME[I].Alignment:=taCenter;
            FBNAME[I].Expression:=''''SUM(QUERY.''''+Query.Fields[I].FieldName+'''')'''';
            FBNAME[I].BringToFront;
          end;
        end;

        if Tj2.Checked then begin  //是否建立总和带区?
          SumShape[I]:=TQRShape.Create(SB); //建立总和带区线条控件
          SumShape[I].Parent:=SB;
          SumShape[I].Top:=0;
          SumShape[I].Left:=CHBlf;
          SumShape[I].Width:=ObWidth+1;
          SumShape[I].Height:=17;

          if (Query.Fields[I].DataType=ftFloat) or
             (Query.Fields[I].DataType=ftCurrency) or (I<2) then
          begin   //如果字段类型为数值类型则建立
            SumNAME[I]:=TQRExpr.Create(SB);  //建立总和带区控件
            SumNAME[I].Parent:=SB;
            SumNAME[I].ParentReport:=QuickRep;
            SumNAME[I].Top:=3;
            SumNAME[I].Left:=CHBlf+2;
            SumNAME[I].AutoSize:=False;
            SumNAME[I].Width:=ObWidth-3;
            SumNAME[I].Height:=13;
            SumNAME[I].Alignment:=taCenter;
            SumNAME[I].Expression:=''''SUM(QUERY.''''+Query.Fields[I].FieldName+'''')'''';
            SumNAME[I].BringToFront;
          end;
        end;
        CHBlf:=CHBlf+ObWidth;//当前字段处理完成,往右一个字段宽度
      end;
    end;
  end;
  CrtRep.Enabled:=False;//禁上生成按钮
  BtnPrint.Enabled:=not CrtRep.Enabled;允许打印铵钮
  BtnPrview.Enabled:=BtnPrint.Enabled;允许预览按钮
  if Tj1.Checked then begin  //如果建立了页脚带区,则将页脚带区中前两列更改
    FBNAME[0].Expression:=''''''''''''页合计'''''''''''';
    FBNAME[1].Expression:=''''COUNT+''''''''行'''''''''''';
  end;
  if Tj1.Checked then begin  //如果建立了总和带区,则将总和带区中前两列更改
    SumNAME[0].Expression:=''''''''''''总计'''''''''''';
    SumNAME[1].Expression:=''''COUNT+''''''''行'''''''''''';
  end;
  //调整列标头带区中的日期及页码打印位置
  QRE2.Left:=HB.Width-Qre2.Width;
  QRSQL.Left:=QRE1.Width+10;
  QRSQL.Width:= QRE2.Left-10-QRSQL.Left;
  QuickRep.DataSet:=Query;  //为QuickRep指定数据集,该句一定不能少
  Screen.Cursor:=crDefault;
end;

procedure TPrintForm.ClearRep();//清除生成报表格式时建立的控件
Var
  I:Byte;
begin
  For I:=0 to Query.FieldCount-1 do  begin
    if Assigned(CHBShape[I]) then begin CHBShape[I].Free;CHBShape[I]:=nil;end;
    if Assigned(CHBNAME[I]) then begin CHBNAME[I].Free;CHBNAME[I]:=nil;end;
    if Assigned(DBShape[I]) then begin DBShape[I].Free;DBShape[I]:=nil;end;
    if Assigned(DBNAME[I]) then begin DBNAME[I].Free;DBNAME[I]:=nil;end;
    if Assigned(FBShape[I]) then begin FBShape[I].Free;FBShape[I]:=nil;end;
    if Assigned(FBNAME[I]) then begin FBNAME[I].Free;FBNAME[I]:=nil;end;
    if Assigned(SumShape[I]) then begin SumShape[I].Free;SumShape[I]:=nil;end;
    if Assigned(SumNAME[I]) then begin SumNAME[I].Free;SumNAME[I]:=nil;end;
  end;
end;

procedure TPrintForm.SRClick(Sender: TObject);
begin
  if Sr.Checked then QrSQL.Caption:=CXTJ else QRSQL.Caption:='''''''';
end;

procedure TPrintForm.FormShow(Sender: TObject);  //窗体显示事件
begin
  Query.Active:=True;//打印SQL
  TT.Text:=Bt;
  QuickRep.ReportTitle:=Bt;//设置标题
  //控件名数组分配空间
  SetLength(CHBNAME,Query.FieldCount);
  SetLength(CHBShape,Query.FieldCount);
  SetLength(DBNAME,Query.FieldCount);
  SetLength(DBShape,Query.FieldCount);
  SetLength(FBNAME,Query.FieldCount);
  SetLength(FBShape,Query.FieldCount);
  SetLength(SumNAME,Query.FieldCount);
  SetLength(SumShape,Query.FieldCount);
end;

procedure TPrintForm.PaperSizeChg(Sender: TObject);
begin
  CrtRep.Enabled:=True;
  BtnPrint.Enabled:=not CrtRep.Enabled;
  BtnPrview.Enabled:=BtnPrint.Enabled;
end;

procedure TPrintForm.DJChage(Sender: TObject);//对齐方式改变事件处理
var
  Chg:Byte;
begin
  if Djauto.Checked then Chg:=0
    else if DjCenter.Checked then Chg:=1
      else Chg:=2;
  if Chg<>Rd1 then begin PaperSizeChg(nil);Rd1:=Chg;end;
end;

procedure TPrintForm.WdChage(Sender: TObject);//宽度改变事件处理
var
  Chg:Byte;
begin
  if Wdauto.Checked then Chg:=0
    else if Wdall.Checked then begin
                                 Chg:=1;
                                 if ColWd.Text='''''''' then ColWd.Text:=''''100'''';
                             

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


没有相关教程
教程录入:mintao    责任编辑:mintao 
  • 上一篇教程:

  • 下一篇教程:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
      注:本站部分文章源于互联网,版权归原作者所有!如有侵权,请原作者与本站联系,本站将立即删除! 本站文章除特别注明外均可转载,但需注明出处! [MinTao学以致用网]
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)

    同类栏目
    · C语言系列  · VB.NET程序
    · JAVA开发  · Delphi程序
    · 脚本语言
    更多内容
    热门推荐 更多内容
  • 没有教程
  • 赞助链接
    更多内容
    闵涛博文 更多关于武汉SEO的内容
    500 - 内部服务器错误。

    500 - 内部服务器错误。

    您查找的资源存在问题,因而无法显示。

    | 设为首页 |加入收藏 | 联系站长 | 友情链接 | 版权申明 | 广告服务
    MinTao学以致用网

    Copyright @ 2007-2012 敏韬网(敏而好学,文韬武略--MinTao.Net)(学习笔记) Inc All Rights Reserved.
    闵涛 投放广告、内容合作请Q我! E_mail:admin@mintao.net(欢迎提供学习资源)

    站长:MinTao ICP备案号:鄂ICP备11006601号-18

    闵涛站盟:医药大全-武穴网A打造BCD……
    咸宁网络警察报警平台