zoukankan      html  css  js  c++  java
  • 关于FastReport

    今天开始研究FastReport。

    1. 以下是动态创建FASTREPORT的DEMO

    var

    Page: TfrxReportPage;

    Band: TfrxBand;

    DataBand: TfrxMasterData;

    Memo: TfrxMemoView;

    begin

    { clear a report }

    frxReport1.Clear;

    { add a dataset to the list of ones accessible for a report }

    frxReport1.DataSets.Add(frxDBDataSet1);

    { add a page }

    Page := TfrxReportPage.Create(frxReport1);

    { create a unique name }

    Page.CreateUniqueName;

    { set sizes of fields, paper and orientation by default }

    Page.SetDefaults;

    { modify paper's orientation }

    Page.Orientation := poLandscape;

    { add a report title band}

    Band := TfrxReportTitle.Create(Page);

    Band.CreateUniqueName;

    { it is sufficient to set the «Top» coordinate and height for a band }

    { both coordinates are in pixels }

    Band.Top := 0;

    Band.Height := 20;

    { add an object to the report title band }

    Memo := TfrxMemoView.Create(Band);

    Memo.CreateUniqueName;

    Memo.Text := 'Hello FastReport!';

    Memo.Height := 20;

    { this object will be stretched according to band's width }

    Memo.Align := baWidth;

    { add the masterdata band }

    DataBand := TfrxMasterData.Create(Page);

    DataBand.CreateUniqueName;

    DataBand.DataSet := frxDBDataSet1;

    { the Top coordinate should be greater than the previously added band's

    top + height}

    DataBand.Top := 100;

    DataBand.Height := 20;

    { add an object on master data }

    Memo := TfrxMemoView.Create(DataBand);

    Memo.CreateUniqueName;

    { connect to data }

    Memo.DataSet := frxDBDataSet1;

    Memo.DataField := 'xm';

    Memo.SetBounds(0, 0, 100, 20);

    { adjust the text to the right object's margin }

    Memo.HAlign := haRight;

    { show the report }

    frxReport1.ShowReport;

    1. FastReport问题整理

    http://blog.163.com/ex_plus/blog/static/1795953220090811151264/

    1. FastReport 程序员手册    

    http://www.evget.com/zh-CN/Info/ReadInfo.aspx?id=9451

           

    1. 通用打印模块。

    在系统中经常需要用到对已经得到的数据集,进行打印。为此特意制作了该单元

    {hl created 20090423

    提供通用打印功能

         

    }

    unit DfReportFrm;

         

    interface

         

    uses

    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

    Dialogs, frxDesgn, frxClass, Db, frxDBSet, dbClient, frxVariables;

         

    type

    TPrintType = (ptPrint, ptPreview, ptDesign, ptAllDesign);

         

    TDfReportForm = class(TForm)

    frxReport: TfrxReport;

    frxDesigner: TfrxDesigner;

    private

    { Private declarations }

    frxDBDataset: TfrxDBDataset;

    ClientDataSet: TCustomClientDataSet;

    frxVariable: TfrxVariable;

         

    public

    { Public declarations }

    //向报表中增加数据集

    procedure AddDataSet(ADataSetArray: array of TDataSet;

    AData: Variant; AServerDate: TDateTime);

    end;

         

    procedure _DfPrintReport(ADataSetArray: array of TDataSet; APrintType: TPrintType;

    AData: Variant; ATemplateFileName: string = ''; AServerDate: TDateTime = 0); overload;

         

    procedure _DfPrintReport(ADataSetArray: array of TDataSet; APrintType: TPrintType;

    AData: Variant; ATemplateStream: TStream; AServerDate: TDateTime = 0); overload;

         

         

    implementation

         

    {$R *.dfm}

         

         

    procedure _DfPrintReport(ADataSetArray: array of TDataSet; APrintType: TPrintType;

    AData: Variant; ATemplateFileName: string = ''; AServerDate: TDateTime = 0);

    var

    DfReportForm: TDfReportForm;

    begin

    DfReportForm := TDfReportForm.Create(Application);

    try

    with DfReportForm.frxReport do

    begin

    Clear;

    //装载数据

    DfReportForm.AddDataSet(ADataSetArray, AData, AServerDate);

    if FileExists(ATemplateFileName) then

    LoadFromFile(ATemplateFileName);

    // ReportOptions.Name := ARptName;

         

    //显示

    case APrintType of

    ptPrint: begin //打印

    if PrepareReport() then

    Print;

    end;

         

    ptPreview: //预览

    ShowReport;

         

    ptDesign, ptAllDesign: begin //设计

    FileName := ATemplateFileName;

    DesignReport;

    if Modified then

    begin

    SaveToFile(ATemplateFileName);

    end;

    end;

    end;

    end;

         

    finally

    FreeAndNil(DfReportForm);

    end;

         

    end;

         

    procedure _DfPrintReport(ADataSetArray: array of TDataSet; APrintType: TPrintType;

    AData: Variant; ATemplateStream: TStream; AServerDate: TDateTime = 0);

    var

    DfReportForm: TDfReportForm;

    begin

    DfReportForm := TDfReportForm.Create(Application);

    try

    with DfReportForm.frxReport do

    begin

    Clear;

    //装载数据

    DfReportForm.AddDataSet(ADataSetArray, AData, AServerDate);

       

    ATemplateStream.Position := 0;

    if ATemplateStream.Size > 0 then

    LoadFromStream(ATemplateStream);

    // FileName := ARptName;

    // ReportOptions.Name := ARptName;

    //显示

    case APrintType of

    ptPrint: begin //打印

    if PrepareReport() then

    Print;

    end;

         

    ptPreview: //预览

    ShowReport;

         

    ptDesign, ptAllDesign: begin //设计

    DesignReport;

    if Modified then

    begin

    ATemplateStream.Position := 0;

    SaveToStream(ATemplateStream);

    end;

    end;

    end;

    end;

         

    finally

    FreeAndNil(DfReportForm);

    end;

    end;

    { TDfReportForm }

         

    procedure TDfReportForm.AddDataSet(ADataSetArray: array of TDataSet;

    AData: Variant; AServerDate: TDateTime);

    var

    i: Integer;

    intTmp: Integer;

    begin

    frxReport.DataSets.Clear;

    for i := 0 to Length(ADataSetArray) - 1 do

    begin

    frxDBDataset := TfrxDBDataset.Create(Self);

    frxDBDataset.Name := ADataSetArray[i].Name;

    frxDBDataset.DataSet := ADataSetArray[i];

         

    frxReport.DataSets.Add(frxDBDataset);

    end;

    //传入自定义数据

    if AData <> null then

    begin

    ClientDataSet := TCustomClientDataSet.Create(Self);

    ClientDataSet.Data := AData;

    frxDBDataset := TfrxDBDataset.Create(Self);

    frxDBDataset.Name := 'SelfDefineData';

    frxDBDataset.DataSet := ClientDataSet;

    frxReport.DataSets.Add(frxDBDataset);

    end;

    intTmp := frxReport.Variables.IndexOf('ServerDate');

         

    if intTmp < 0 then

    begin

    frxVariable := frxReport.Variables.Add;

    frxVariable.Name := 'ServerDate';

    end

    else

    frxVariable := frxReport.Variables.Items[intTmp];

         

    frxVariable.Value := AServerDate;

    end;

         

    end.

         

    使用方法:

    _DfPrintReport([HlAdoClientDataSet1], ptDesign, HlAdoClientDataSet1.Data, 'd:\test.fr3', Now);

     

    1. FASTREPORT中自定义函数的使用

    今天看到同事在写一个REPORT,竟然可以将程序中的函数传递给FASTREPORT写程序的时候使用,感觉很奇怪,研究一下,其实很简单,不过功能很强大。

    主要增加一个UNIT,就可以在这个单元中增加自定义函数了。

    (***********************************************************************

    Fastreport 报表附加函数单元

    LWD, 2009/03/19

    ************************************************************************)

    unit lxbl_RptAddinFunc;

     

    interface

     

    uses fs_iinterpreter;

     

    type

    TRptAddinFuncLib = class(TfsRTTIModule)

    protected

    function CallMethod(Instance: TObject; ClassType: TClass;

    const MethodName: String; var Params: Variant): Variant;

    function SetFwrxx(fwrxm1:string;fwrxm2:string;fwrdw:string):string;

    function SetFwrxmdw(fwrxm1,fwrxm2,fwrdw1,fwrdw2:string):string;

    public

    constructor Create(AScript: TfsScript); override;

    end;

     

    implementation

     

    //uses lxbl_SysUtil;

     

    const

    FUNCLIB_CAT = '离线笔录附加函数';

     

    { TRptAddinFuncLib }

     

    function TRptAddinFuncLib.CallMethod(Instance: TObject; ClassType: TClass;

    const MethodName: String; var Params: Variant): Variant;

    begin

    if MethodName = 'GETSYSDMVALUE' then

    begin

    // Result := TLxblSysUtil.GetSysDmValue(Params[0], Params[1]);

    end

    else if MethodName = 'SETFWRXX' then

    begin

    Result := setFwrxx(Params[0], Params[1], Params[2]);

    end

    else if MethodName = 'SETFWRXMDW' then

    begin

    Result := SetFwrxmdw(Params[0], Params[1], Params[2], Params[3]);

    end

    else if MethodName = 'FORMATDATESTR' then

    begin

    // Result := TLxblSysUtil.FormatDateStr(Params[0],Params[1],Params[2]);

    end;

    end;

     

    function TRptAddinFuncLib.SetFwrxx(fwrxm1: string; fwrxm2: string; fwrdw: string):string;

    var tmpFwrxx:string;

    begin

    if fwrxm1<>'' then

    tmpFwrxx := fwrxm1;

    if fwrxm2<>'' then

    tmpFwrxx := tmpFwrxx + '、' + fwrxm2;

    if fwrdw<>'' then

    tmpFwrxx := tmpFwrxx + ',' + fwrdw;

    result := tmpFwrxx;

    end;

     

    function TRptAddinFuncLib.SetFwrxmdw(fwrxm1,fwrxm2,fwrdw1,fwrdw2: string):string;

    var tmpFwrxmdw:string;

    begin

    if(fwrdw1=fwrdw2)then

    begin

    if fwrxm1<>'' then

    tmpFwrxmdw := fwrxm1;

    if fwrxm2<>'' then

    tmpFwrxmdw := tmpFwrxmdw + '、' + fwrxm2;

    if fwrdw1<>'' then

    tmpFwrxmdw := tmpFwrxmdw + ',' + fwrdw1;

    end

    else

    begin

    if fwrxm1<>'' then

    begin

    tmpFwrxmdw := fwrxm1;

    if fwrdw1<>'' then

    tmpFwrxmdw := tmpFwrxmdw + ',' + fwrdw1;

    end;

    if fwrxm2<>'' then

    begin

    tmpFwrxmdw := tmpFwrxmdw + ';' + fwrxm2;

    if fwrdw2<>'' then

    tmpFwrxmdw := tmpFwrxmdw + ',' + fwrdw2;

    end;

    end;

    result := tmpFwrxmdw;

    end;

     

    constructor TRptAddinFuncLib.Create(AScript: TfsScript);

    begin

    inherited Create(AScript);

    with AScript do

    begin

    AddMethod('function GetSysDmValue(flagtype: string; lagid: string):string',

    CallMethod, FUNCLIB_CAT, '根据代码返回相应的值');

    AddMethod('function SetFwrxx(fwrxm1: string; fwrxm2: string; fwrdw: string):string',

    CallMethod, FUNCLIB_CAT, '设置发问人信息');

    AddMethod('function SetFwrxmdw(fwrxm1,fwrxm2,fwrdw1,fwrdw2:string):string',

    CallMethod, FUNCLIB_CAT, '设置发问人姓名单位');

    AddMethod('function FormatDateStr(dateStr: string; oldFmt: string; newFmt: string):string',

    CallMethod, FUNCLIB_CAT, '转换日期格式');

    end;

    end;

     

    initialization

    fsRTTIModules.Add(TRptAddinFuncLib);

    end.

    代码来自一同事的朋友,赞一个!

  • 相关阅读:
    Jenkins修改用户密码及权限
    Selenium知识点小结
    解析图形验证码登录系统
    Pywinauto实现电脑客户端有道云签到领空间
    Python冒泡排序
    LoadRunner12常用函数
    GIT教程笔记
    LoadRunner 关联
    搭建自动化测试框架Python3+Selenium
    SSH免密从A服务器登录进B服务器,重启B服务器的tomcat
  • 原文地址:https://www.cnblogs.com/barryhong/p/1423254.html
Copyright © 2011-2022 走看看