FastReport 如何封装成DLL供VB6、PB等调用

lovesmileman 2010-08-06 02:30:58
FastReport 如何封装成DLL供 VB6、PB 等调用开发工具调用。
非常感谢。小弟Delphi比较弱,麻烦说详细点。拜谢!
...全文
589 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
xyzdelphi 2010-08-09
  • 打赏
  • 举报
回复
晕,还有人用PB 呀,也太老了吧!
kye_jufei 2010-08-09
  • 打赏
  • 举报
回复
但是特別注意:

在dll中使用FastReport会遇到以下内个问题:
1.调用时变量出错,最普通的一个变量注入也是一样
2.出现Cannot assign a TFieldList to a TStringList的错误
3.Invalid pointer operation的错误,在函数中返回WideString引起的

以下是解决办法:

1.不要在DLL中直接引用FastReport的单元文件,最好用一个接口类来实现 ,做法如下:
a.定义公共类接口
b.在主程序中实现该接口类
c.把接口类的实例指针传给DLL
d.在dll中调用公共类的方法,以实现注入变量与数据集的功能
2.修改frxDBSet.pas中的procedure TfrxDBDataset.GetFieldList(List: TStrings);
var
i: Integer;
begin
List.Clear;
if FieldAliases.Count = 0 then
begin
try
if FDS <> nil then
for i := 0 to FDS.FieldCount - 1 do //<--新加的
List.Add(FDS.Fields[i].FullName); //<--新加的
//FDS.GetFieldNames(List); //<--旧的函数
except
end;
end
else
begin
for i := 0 to FieldAliases.Count - 1 do
if Pos('-', FieldAliases.Names[i]) <> 1 then
List.Add(FieldAliases.Values[FieldAliases.Names[i]]);
end;
end;


3.非常重要的一点,要在主程序和DLL中都引用ShareMem单元文件,否则在获取数据集显示的字符串时将出现错误!跟踪一下就知道了...

 
kye_jufei 2010-08-09
  • 打赏
  • 举报
回复
对应dll接口;

library Fr_Report;

{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }

uses
ShareMem,
Windows,
SysUtils,
Classes,
Forms,
ADODB,
DB,
UnitFrmReport in 'UnitFrmReport.pas' {FrmReport},
WinSkinData,
UnitFrmReportEdit in 'UnitFrmReportEdit.pas' {FrmReportEdit},
UnitPrintFrm in 'UnitPrintFrm.pas' {PrintFrm};

{$R *.res}
var
DllApplication: TApplication;
//根据窗口名称/报表编号打印/预览报表;
//参数列表
//App:当前工程;
//adata 皮肤窗口需要传得参数;
//con:数据库格式文件存储的数据库联接;
//datalist:打印的数据集列表;
//Frmname:窗口名称;
function ShowReportFrm(app:TApplication;adata: Pointer;con:TADOConnection;
dataList:TList;FrmName:string):Boolean;stdcall;
begin
Result:=False;
application:=app;
Winskindata.SkinDll(adata);
FrmReport:=TFrmReport.Create(app);
if Assigned(dataList) then
FrmReport.DataList:=dataList;
FrmReport.frmname:=frmname;
frmReport.adoSetMain.Connection:=con;
FrmReport.adoSetMain.CommandText:='select * from ReportFileRec where FrmName='+#39+FrmName+#39;
FrmReport.adoSetMain.Open;
FrmReport.ShowModal;
FrmReport.Free;
Result:=True;
end;

function GetReportList(app:TApplication;con:TADOConnection;FrmName:string;var Strs: TStrings):boolean;stdcall;
var
adoset:TADODataSet;
i:integer;
begin
application:=app;
adoset:=TADODataSet.Create(nil);
adoset.Connection:=con;
adoset.CommandText:='select * from ReportFileRec where FrmName='+#39+FrmName+#39;
adoset.Open;
if not adoset.IsEmpty then
begin
adoset.First;
for i:=0 to adoset.RecordCount-1 do
begin
Strs.Add(adoset.fieldbyname('ReportName').Value);
adoset.Next;
end;
end;
adoset.Free;
end;

function ShowPrint(app:TApplication;adata: Pointer;conn:TADOConnection;
dataList:TList;ReportName:string;lmode:boolean):boolean;stdcall;
var
Dataset:TADODataSet;
i:integer;
begin
Result:=false;
application:=app;
Winskindata.SkinDll(adata);
Dataset:=TADODataSet.Create(nil);
Dataset.CommandText:='Select * from ReportFileRec where ReportName='+#39+ReportName+#39;
Dataset.Connection:=conn;
Dataset.Open;
if Dataset.IsEmpty then Exit;
ShowReport(dataList,TBlobField(dataset.FieldByName('ReportFile2')),lmode,Reportname);
dataset.Free;
end;

procedure DLLUnloadProc(Reason: Integer); register;
begin
if Reason = DLL_PROCESS_DETACH then
begin
Application:=DllApplication;
end;
end;

exports
ShowReportFrm,
ShowPrint,
GetReportList;

begin
DllApplication:=Application;
DLLProc := @DLLUnloadProc;
end.
kye_jufei 2010-08-09
  • 打赏
  • 举报
回复
静态引用接口:

function ShowReportFrm(app:TApplication;adata: Pointer;con:TADOConnection;
dataList:TList;FrmName:string):Boolean;stdcall;external 'Fr_Report.dll';

function GetReportList(app:TApplication;con:TADOConnection;FrmName:string;var Strs: TStringList):boolean;stdcall;external 'Fr_Report.dll';

function ShowPrint(app:TApplication;adata: Pointer;conn:TADOConnection;
dataList:TList;ReportName:string;lmode:boolean):boolean;stdcall;external 'Fr_Report.dll';
lovesmileman 2010-08-06
  • 打赏
  • 举报
回复
期待高手指点!!!
亮剑_ 2010-08-06
  • 打赏
  • 举报
回复
FastReport官方只提供for Delphi 和 for .NET 版本
自行封装可搜索
http://www.google.com.hk/search?hl=zh-CN&q=FastReport+dll
lovesmileman 2010-08-06
  • 打赏
  • 举报
回复
本人是Delphi菜鸟
无语孩童 2010-08-06
  • 打赏
  • 举报
回复
楼主会用Delphi谢DLL吗?

5,392

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧