zoukankan      html  css  js  c++  java
  • DLL封装ReportMachine/FastReport报表

    如果有报表文件兼容性问题,可以参考下面的方法来将某版本的报表封装到DLL中来使用。
    首先建立一个DLL工厂,然后建立一个主窗体,在窗体中放入报表相关的控件。

    为了传入变量,我们简单定义一个变量名称/值对应用的对象:

    //变量对应,可以用于变量和对象
      RMVariants
    =class
        VarName:
    string;
        VarValue:
    string;
      
    end;

    然后定义一个输出函数:

    procedure ShowReport(vFile:string;vDSList:TList;vVarValueList:TList=nil);stdcall;
    var
      i:Integer;
      aDataSet:TADODataSet;
      aRMDBDataSet:TRMDBDataSet;
      aRMVariants:RMVariants;
    begin
      
    try
        frmReport:
    =TfrmReport.Create(nil);
        
    with frmReport do
        
    begin
          RMReport1.LoadFromFile(vFile);

          
    //创建结果集列表
          
    if vDSList<>nil then
          
    for I := 0 to vDSList.Count - 1 do
          
    begin
            aDataSet:
    =TADODataSet.Create(nil);
            aDataSet.Clone(TADODataSet(vDSList[i]));
            aDataSet.Name:
    =TDataSet(vDSList[i]).Name;

            aRMDBDataSet:
    =TRMDBDataSet.Create(nil);
            aRMDBDataSet.DataSet:
    =aDataSet;
            aRMDBDataSet.Name:
    ='RMDB'+aDataSet.Name;

            InsertComponent(aDataSet);
            InsertComponent(aRMDBDataSet);
          
    end;

          
    //对变量进行赋值
          
    if vVarValueList<>nil then
          
    for I := 0 to vVarValueList.Count - 1 do
          
    begin
            aRMVariants:
    =RMVariants(vVarValueList[i]);
            RMReport1.Dictionary.Variables[aRMVariants.VarName] :
    =aRMVariants.VarValue;
          
    end;

          RMReport1.ShowReport
        
    end;
      
    finally
        frmReport.Free;
      
    end;
    end;

    然后在需要的时候调用该DLL即可。

    上面代码使用了ADO,为了更通用,可以使用ClientDataSet来处理数据,在窗体中放在TDataSetProvider和TClientDataSet来处理结果集,如果不想发布Midas.dll,可以引用单元MidasLib

    注:以上示例使用了ReportMachine,同样适用于FastReport.

  • 相关阅读:
    Double-Array Trie 原理解析
    LeetCode 之 Longest Valid Parentheses(栈)
    [Unity3D]Unity3D游戏开发之从Unity3D到Eclipse
    走进Struts2(一) — Struts2的执行流程及其工作原理
    网页页面NULL值对浏览器兼容性的影响
    基于cocos2d-x-3.2学习Box2D(一)
    记忆方法与高速阅读——什么是高速阅读
    ArcGIS 教程:Workflow Manager 高速浏览
    【cocos2d-x 3.7 飞机大战】 决战南海I (三) 敌机实现
    C语言事实上不简单:数组与指针
  • 原文地址:https://www.cnblogs.com/GarfieldTom/p/1740553.html
Copyright © 2011-2022 走看看