我在dll中用ado完成数据的读取。现应用程序如何获取dll中的数据集,并显示在dbgrid中呢?我在report.dll中是这样写的
function ReportKMYE(handle:THandle;Pathstr:string): TDataSet;StdCall;
begin
Application.Handle :=handle;
dlldm:=Tdlldm.Create(application);
dlldm.ADOQReport.SQL.Text := 'select * from table1';
dlldm.ADOQReport.Open;
Result:= dlldm.ADOQReport ;
end;在应用程序中
procedure TForm1.NRepKmyeClick(Sender: TObject);
var
libHandle:thandle;
ReportKMYE:TReportKMYE;
begin
try
libHandle:=LoadLibrary('report.dll');
@ReportKMYE:=GetProcAddress(libHandle,pchar('ReportKMYE'));
if not Assigned(ReportKMYE) then
raise exception.Create('error')
else
begin
dm1.ds12.DataSet:=ReportKMYE(application.handle,pathstr) ;
DBGrid1.DataSource:=dm1.ds12;
end;
finally
Freelibrary(LibHandle);
end;
end;
包错“Invalid Pointer Operation”
盼指教!!急!在线等待!!!
function ReportKMYE(handle:THandle;Pathstr:string): TDataSet;StdCall;
begin
Application.Handle :=handle;
dlldm:=Tdlldm.Create(application);
dlldm.ADOQReport.SQL.Text := 'select * from table1';
dlldm.ADOQReport.Open;
Result:= dlldm.ADOQReport ;
end;在应用程序中
procedure TForm1.NRepKmyeClick(Sender: TObject);
var
libHandle:thandle;
ReportKMYE:TReportKMYE;
begin
try
libHandle:=LoadLibrary('report.dll');
@ReportKMYE:=GetProcAddress(libHandle,pchar('ReportKMYE'));
if not Assigned(ReportKMYE) then
raise exception.Create('error')
else
begin
dm1.ds12.DataSet:=ReportKMYE(application.handle,pathstr) ;
DBGrid1.DataSource:=dm1.ds12;
end;
finally
Freelibrary(LibHandle);
end;
end;
包错“Invalid Pointer Operation”
盼指教!!急!在线等待!!!
TEntry = function(PubInfo:TPublicInfo):TForm; stdcall;
而你的dll中实际export也是 Tentry,这样等同于大家共享了一段数据区PublicInfo.若你的Publciinfo包含了如一个Tdataset,不就行了.
我可能讲的不清楚.但意思如下:
1.主程序和dll都包含了某个单元.这个单元的某一数据区为共享的.在这数据区内你可以包含你要传递的数据,结构等.但要定义一个函数.
2.dll也必须export此函数.
我自己目前也是这种写法!