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

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

作者:闵涛 文章来源:闵涛的学习笔记 点击数:3050 更新时间:2009/4/23 18:42:10
,QuickRep.Page.BottomMargin);
  PageLeft.Text:=FormatFloat(''''0.00'''',QuickRep.Page.LeftMargin);
  PageRight.Text:=FormatFloat(''''0.00'''',QuickRep.Page.RightMargin);
  PageSpace.Text:=FormatFloat(''''0.00'''',QuickRep.page.ColumnSpace);
  R1.Checked:=QuickRep.Page.Orientation=poPortrait;
  Image1.Visible:=R1.Checked;
  R2.Checked:=QuickRep.Page.Orientation=poLandscape;
  Image2.Visible:=R2.Checked;
  PageDlux.Checked:=QuickRep.PrinterSettings.Duplex;
  Pages.Text:=IntToStr(QuickRep.PrinterSettings.Copies);
  PaperH.Text:=FormatFloat(''''0.00'''',QuickRep.Page.Length);
  PaperW.Text:=FormatFloat(''''0.00'''',QuickRep.Page.Width);
  For I:=0 to 26 do     //PS列表框显示纸张类型
    if QuickRep.Page.PaperSize=PaperSize[I] then begin
       PS.ItemIndex:=I;
       Break;
end;
//判断纸张宽度是否可以更改,只有纸张类型为自定义(Ps.ItemIndex=26)才能更改
  PaperH.Enabled:=Ps.ItemIndex=26;
  PaperW.Enabled:=Ps.ItemIndex=26;
end;

procedure TPrintForm.RadioButtonClick(Sender: TObject);
//纸张方向改变事件处理
var
  S:String;
begin
  Image1.Visible:=R1.Checked;
  Image2.Visible:=R2.Checked;
  if R1.Checked then
    QuickRep.Page.Orientation:=poPortrait
  else
    QuickRep.Page.Orientation:=poLandscape;
  //交换纸张宽度和长度的值
  S:=PaperH.Text;
  PaperH.Text:=PaperW.Text;
  PaperW.Text:=S;
  if (Ps.ItemIndex=26) or (Ps.ItemIndex=0) then begin
    QuickRep.Page.Width:=StrToFloat(PaperW.Text);
    QuickRep.Page.Length:=StrToFloat(PaperH.Text);
  end;
end;

procedure TPrintForm.PageDluxClick(Sender: TObject);
begin
  QuickRep.PrinterSettings.Duplex:=PageDlux.Checked;
end;

procedure TPrintForm.PageColChange(Sender: TObject);
begin
  if StrToInt(PageCol.Text)<1 then PageCol.Text:=''''1'''';
  QuickRep.Page.Columns:=StrToInt(PageCol.Text);
end;

procedure TPrintForm.PageSpaceExit(Sender: TObject);
begin
  QuickRep.Page.ColumnSpace:=StrToFloat(PageSpace.Text);
end;

procedure TPrintForm.PagesChange(Sender: TObject);
begin
  if StrToInt(Pages.Text)<1 then Pages.Text:=''''1'''';
  QuickRep.PrinterSettings.Copies:=StrToInt(Pages.Text);
end;

procedure TPrintForm.PageTopExit(Sender: TObject);
begin
  QuickRep.Page.TopMargin:=StrToFloat(PageTop.Text);
end;

procedure TPrintForm.PageBottomExit(Sender: TObject);
begin
  QuickRep.Page.BottomMargin:=StrToFloat(PageBottom.Text);
end;

procedure TPrintForm.PageLeftExit(Sender: TObject);
begin
  QuickRep.Page.LeftMargin:=StrToFloat(PageLeft.Text);
end;

procedure TPrintForm.PageRightExit(Sender: TObject);
begin
  QuickRep.Page.RightMargin:=StrToFloat(PageRight.Text);
end;

procedure TPrintForm.TTExit(Sender: TObject);//标题更改事件处理
begin
  QuickRep.ReportTitle:=TT.Text;
  Title.Caption:=TT.Text;
  Bt:=TT.Text;
end;

procedure TPrintForm.DTClick(Sender: TObject);//打印查询条件复选框事件
begin
  QRSQL.Enabled:=SR.Checked;
end;

procedure TPrintForm.BtnPrviewClick(Sender: TObject);//预览按钮单击事件
begin
  QuickRep.Preview;
end;

procedure TPrintForm.BtnSetClick(Sender: TObject); //设置按钮单击事件
begin
  QuickRep.PrinterSetup;
end;

procedure TPrintForm.PsChange(Sender: TObject);//纸张类型改变事件
begin
  QuickREp.Page.PaperSize:=PaperSize[Ps.ItemIndex];
  PaperH.Text:=FormatFloat(''''0.00'''',QuickRep.Page.Length);
  PaperW.Text:=FormatFloat(''''0.00'''',QuickRep.Page.Width);
  PaperH.Enabled:=Ps.ItemIndex=26;
  PaperW.Enabled:=Ps.ItemIndex=26;
  CrtRep.Enabled:=True;
  BtnPrint.Enabled:=not CrtRep.Enabled;
  BtnPrview.Enabled:=BtnPrint.Enabled;
end;

procedure TPrintForm.PaperChange(Sender: TObject);//纸张宽度和长度改变事件
begin
  QuickRep.Page.Width:=StrToFloat(PaperW.Text);
  QuickRep.Page.Length:=StrToFloat(PaperH.Text);
end;

procedure TPrintForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action:=caFree;
end;

procedure TPrintForm.FormDestroy(Sender: TObject);
begin
  ClearRep;
  PrintForm:=nil;
end;

procedure TPrintForm.CreateReport(Sender: TObject);//生成按钮单击事件
Var
  I,L:Byte;
  CHBtp,CHBlf,Cd,ObWidth:Word;
begin
  Screen.Cursor:=crHourGlass;
  Title.Caption:=Bt;//设置标题
  ClearRep(); //清除已经建立的对象;
  if Sr.Checked then QrSQL.Caption:=CXTJ else QRSQL.Caption:='''''''';//是否打印查询条件?
  CHBtp:=HB.Height-17;//建立的控件在带区中的顶部位置
  CHBlf:=0; //建立的控件在带区中的左边位置
  ObWidth:=0; //建立的控件的宽度
  for I := 0 to Query.FieldCount-1 do    //根据Query返回字段数建立控件
  begin
if (Query.Fields[I].DataType<>ftBlob) And (Query.Fields[I].DataType<>ftMemo) then    
begin    //忽略备注字段和相片字段
      L:=Query.Fields[I].DataSize-1;//L=字段宽度(字节)-1
      case Rd1 of   //根据选择的对齐方式设置控件的对齐方式
        0: if L<=10 then Dj:=taCenter else DJ:=taLeftJustify;
        //自动对齐:字段小于等于10居中对齐,否则左边对齐
        1: Dj:=taCenter;//居中对齐
        2: DJ:=taLeftJustify;//左边对齐
      end;
      case Rd2 of    //根据选择的列表宽度设置报表列宽度
        0: begin    
       //自动宽度:如果L>14则宽度ObWidth=14+(L-14)/2;如果ObWidth
       //的宽度不能显示列标题,则ObWidth=列标题宽度;如果字段类型
       //为日期型、货币型和浮点数型,则ObWidth=65
             if L>14 then L:=14+(L-14) div 2;
             ObWidth:=L*6;
             L:=Length(Query.Fields[I].DisplayName);
             if ObWidth<L*6 then ObWidth:=L*6;
             ObWidth:=ObWidth+2;
             if (Query.Fields[I].DataType=ftDateTime) or
                (Query.Fields[I].DataType=ftFloat) or
                (Query.Fields[I].DataType=ftCurrency) then ObWidth:=65;
           end;
        1: if ColWd.Text<>'''''''' then ObWidth:=StrToInt(ColWd.Text)
              else ObWidth:=100;//相同宽度:ObWidth=输入宽度值
        2: begin  //限制最大宽度:首先按自动宽度计算再判断宽度是否超最大值,
                  //如果超过则ObWidth=最大宽度输入值
             if ColWd.Text<>'''''''' then Cd:=StrToInt(ColWd.Text)
                else Cd:=200;
             ObWidth:=L*6;
             if ObWidth>Cd then ObWidth:=Cd;
             ObWidth:=ObWidth+2;
             if (Query.Fields[I].DataType=ftDateTime) or
                (Query.Fields[I].DataType=ftFloat) or
                (Query.Fields[I].DataType=ftCurrency) then ObWidth:=65;
           end;
      end;

      if CHBlf+ObWidth>=HB.Width then begin  //建立控件>纸宽?
        DlgMes:=''''纸张宽度不够,请更改纸张尺寸。'''';
        MessageBox(Handle,DlgMes,Cap_Inf,Ico_Inf);
        break;
      end
      else begin
        CHBShape[I]:=TQRShape.Create(HB);//建立列标头带区线条控件
        CHBShape[I].Parent:=HB;
        CHBShape[I].Top:=CHBtp;
        CHBShape[I].Left:=CHBlf;
        CHBShape[I].Width:=ObWidth+1;
        CHBShape[I].Height:=17;

        CHBNAME[I]:=TQRLabel.Create(HB); //建立列标题控件
        CHBNAME[I].Parent:=HB;
        CHBNAME[I].Top:=CHBtp+2;
        CHBNAME[I].Left:=CHBlf+1;
        CHBNAME[I].AutoSize:=False;
        CHBNAME[I].Width:=ObWidth-1;
 

上一页  [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……
    咸宁网络警察报警平台