5,392
社区成员
发帖
与我相关
我的任务
分享
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;
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.
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';