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

lovesmileman 2010-08-06 02:30:58
FastReport 如何封装成DLL供 VB6、PB 等调用开发工具调用。
非常感谢。小弟Delphi比较弱,麻烦说详细点。拜谢!
...全文
668 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吗?
内容概要:SSD2828QN4是一款MIPI主桥接芯片,用于连接应用处理器与传统并行LCD接口及支持MIPI从属接口的LCD驱动器。该芯片支持最高每通道1Gbps的串行链路速度,最多可配置4个数据通道,显著减少了信号数量。它支持多种接口模式,包括RGB+SPI组合接口,适用于驱动智能或非智能显示面板,并能通过命令模式和视频模式传输数据。芯片内置时钟和复位模块、外部接口、协议控制单元(PCU)、包处理单元(PPU)、错误校正码/循环冗余校验(ECC/CRC)模块、长包和命令缓冲区、D-PHY控制器、模拟收发器以及内部锁相环(PLL),确保了高效的数据传输和系统稳定性。此外,文档详细描述了芯片的引脚分配、寄存器设置、操作模式、电源序列、时序特性等关键参数,为开发者提了全面的技术指导。 适合人群:具备一定硬件设计基础,从事嵌入式系统开发、显示技术研究的研发人员。 使用场景及目标:①实现应用处理器与MIPI兼容显示屏之间的高速数据传输;②优化显示系统的功耗表现,减少电磁干扰(EMI);③通过灵活配置不同接口模式来适应各种显示设备的需求。 阅读建议:此文档面向具有一定电子工程背景的专业人士,建议读者结合实际项目需求深入理解各章节内容,特别是关于寄存器配置、时序要求等方面的具体说明。对于初次接触此类技术的开发者而言,建议先熟悉基本概念再逐步掌握高级功能的应用方法。

5,943

社区成员

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

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