DLl中DataSet如何传?(100分)

Z

zxl893

Unregistered / Unconfirmed
GUEST, unregistred user!
我已经查了很多,但总有错误。
请给个例子。我的邮箱zxl893@163.com。
 
问题不够清楚!
是不是将主程序中的TDataSet传到DLL中,或反过来?
如果主程序和DLL都是用DELPHI做的,很好办啊!
 
是将DataSet从主程序中传到DLL中。
主程序和DLL都是自已用Delphi编的。
 
试试:

主程序:
var
aDataSet: TDataSet;
DllFun: procedure (DataSet: Pointer)
stdcall;

...
DllFun(Pointer(aDataSet));

DLL:
procedure DllFun(DataSet: Pointer)
stdcall;
TDataSet(DataSet)......
 
wolaixue:主程序关闭时,出现“invalid pointer operation”错误。
 
贴段代码看看.
 
DLL:
interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, DBTables, Grids, DBGrids;

type
TfrmTryOne = class(TForm)
DataSource1: TDataSource;
DBGrid1: TDBGrid;
private
{ Private declarations }
public
{ Public declarations }
end;
procedure OperatorTable(DataSet: Pointer);stdcall;
implementation

{$R *.dfm}
procedure OperatorTable(DataSet: Pointer);stdcall;
begin
with TfrmTryOne.Create(nil) do
try
DataSource1.DataSet:=TDataSet(DataSet);
ShowModal;
finally
Free;
end;
end;

end.

程序:
implementation
procedure OperatorTable(DataSet: Pointer);stdcall;external 'e:/mydll/myfunc/funcs.dll';
{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
OperatorTable(Pointer(Table1));
end;
 
运行时DLL窗口显示正常吗?也就是问Table1传过去了吗?

DataSource1.DataSet:=TDataSet(DataSet);
改成:DataSource1.DataSet:=TTable(DataSet);试试,还有问题,屏蔽之再试.
如果屏蔽了关闭主程序时还有问题,那就不是这里的问题了.
 
将此函数里的DataSet参数改为TDataSet试试。
procedure OperatorTable(DataSet:TDataset);stdcall;
external 'e:/mydll/myfunc/funcs.dll'
 
改了以后也是一样,运行都正常,就是主程序关闭的时候出错。
 
这里说的这些应该不会引起错误的.
 
窗体没有释放。
 
是不是没有包含sharemem这个管理单元
 
最好把主程序的Application.Handle作为参数AppHandle传到DLL中来:
procedure OperatorTable(AppHandle: HWND;DataSet: Pointer);stdcall;
begin
Application.Handle := AppHandle;
with TfrmTryOne.Create(Application) do
try
DataSource1.DataSet:=TDataSet(DataSet);
ShowModal;
finally
Free
//TfrmTryOne的OnClose事件中没有Action := caFree吧?
end;
end;
 
ShareMem加了,
Application.Handle也传了,
Action:=caFree也加了,
还是同样的错误。
 
Action:=caFree不能加!!
如果加了,就不要再Free了!!
 
严重关注(我一直没有解决这个问题)
 
ShareMem要在Uses列表的第一项.无论调用单元还是Dll单元.
 
ShareMem 不是必须的,只有用string类型时才用到.

如果不是窗体Free的问题,可能是DataBase和Session的问题.只能等试过再说了.

你应该跟踪到错误发生的代码上去才好分析.
DB, DBTables单元复制到你的DLL目录,跟踪其Final....部分.
 

Similar threads

顶部