把EXE程序中的数组传递给DLL中的数组,测试报内存错误,请高手指点,谢谢(50分)

  • 主题发起人 richardi
  • 开始时间
R

richardi

Unregistered / Unconfirmed
GUEST, unregistred user!
下面代码中把EXE程序中的APopedom传递给DLL中的APopedom,测试报内存错误,这是为什么?请高人指点,谢谢<br><br>//dll中的单元文件中的调用函数<br>procedure CallForm(const app:TApplication;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;const adocnn:Tadoconnection;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;const aLoginName:string;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Popedom:array of boolean);stdcall;<br>begin<br>&nbsp; Application:=app;<br>&nbsp; if frmPartNo=nil then<br>&nbsp; begin<br>&nbsp; &nbsp; frmPartNo:=TfrmPartNo.Create(app);<br>&nbsp; &nbsp; frmPartNo.ADOConnection1:=adocnn;<br>&nbsp; &nbsp; frmPartNo.LoginName :=aLoginName;<br>&nbsp; &nbsp; frmPartNo.APopedom:=@Popedom;//把参数地址传给frmPartNo.APopedom,这样写不知有没有问题?<br>&nbsp; end;<br>&nbsp; frmPartNo.Show;<br>end;<br>exports<br>&nbsp; CallForm;<br><br>//DLL中的单元<br>unit uPartNo;<br>interface<br>uses<br>&nbsp; Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br>&nbsp; Dialogs, DB, ADODB, StdCtrls, Buttons;<br>type<br>&nbsp; TfrmPartNo = class(TForm)<br>&nbsp; &nbsp; ADOConnection1: TADOConnection;<br>&nbsp; &nbsp; BitBtn1: TBitBtn;<br>&nbsp; &nbsp; procedure BitBtn1Click(Sender: TObject);<br>&nbsp; &nbsp; procedure FormClose(Sender: TObject; var Action: TCloseAction);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; LoginName:string;//声明变量<br>&nbsp; &nbsp; APopedom:array of boolean;//声明数组变量,用于接收exe传递过来的参数<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br>var<br>&nbsp; frmPartNo: TfrmPartNo;<br>implementation<br>{$R *.dfm}<br>procedure TfrmPartNo.BitBtn1Click(Sender: TObject);<br>begin<br>&nbsp; if APopedom[1]=true<br>&nbsp; begin<br>&nbsp; &nbsp; showmessage('ok');//这儿有问题,怎么写法?好像没参数没传过来<br>&nbsp; end;<br>//showmessage(booltostr(APopedom[1]));//测试<br>showmessage(LoginName);<br>end;<br><br>//EXE中的写法<br>&nbsp; PlugIn=function(const app:TApplication;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const adocnn:Tadoconnection;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const aLoginName:string;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Popedom:array of boolean):integer;stdcall;//声明函数类型<br>……<br>procedure TfrmPlms.N5Click(Sender: TObject);<br>var<br>&nbsp; ahandle:THandle;<br>&nbsp; plug:plugIn;<br>begin<br>&nbsp; APopedom[1]:=true;<br>&nbsp; ahandle:=LoadLibrary('pn.dll') ;<br>&nbsp; if ahandle=0 then<br>&nbsp; &nbsp; exit;<br>&nbsp; @plug:=GetProcAddress(ahandle,'CallForm');<br>&nbsp; if @plug&lt;&gt;nil then<br>&nbsp; &nbsp; plug(Application,frmDM.ADOConnection1,'test',APopedom);<br>//传递参数,APopedom变量在EXE文件的声明是APopedom :array[0..160] of boolean;<br>end;
 
K

kinneng

Unregistered / Unconfirmed
GUEST, unregistred user!
APopedom :array[0..160] of boolean;<br>frmPartNo.APopedom:array of boolean;//声明数组变量,用于接收exe传递过来的参数<br>frmPartNo.APopedom:=@Popedom;<br><br>这样根本就是错,frmPartNo.APopedom没设置长度,而且将frmPartNo.APopedom当指针<br>先setlength(frmPartNo.APopedom);然后循环复制每个值
 
R

richardi

Unregistered / Unconfirmed
GUEST, unregistred user!
对,问题就出在数组这里,得怎么修改,我不会写,能给点代码吗?谢谢了
 
K

kinneng

Unregistered / Unconfirmed
GUEST, unregistred user!
setlength(frmPartNo.APopedom, 161);<br>for i:=0 to 160 do frmPartNo.APopedom:=APopedom;
 
R

richardi

Unregistered / Unconfirmed
GUEST, unregistred user!
接受答案了.
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
750
import
I
顶部