如果有报表文件兼容性问题,可以参考下面的方法来将某版本的报表封装到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.

 

posted on 2010-05-21 06:13  garfieldtom  阅读(1638)  评论(0编辑  收藏  举报