调用DLL传递对象数组的有关问题
调用DLL传递对象数组的问题
窗口的对象代码:
加了个按钮,代码:
tkrsdll.dll这个DLL对象的getsz方法:
然后运行窗口点击按钮的时候,就报错了,“Project szcss.exe raised excepton calss EAccessVilation with message 'Access violation at address 03D2358 in module ''tkrsdll.dll'”,
在哪里出问题了呢?
------解决思路----------------------
因为 szcs=array of cs; 这是一个动态数组类型,动态数组的下标要求是整数,而且从0开始,与静态数组不同。
所以你
function getsz(sz:szcs):integer ; stdcall; external 'tkrsdll.dll';
procedure TForm1.Button1Click(Sender: TObject);
var
muserinfo:szcs;
i:integer;
begin
SetLength(muserinfo,1);
for i:=1 to 1 do
begin
muserinfo[i]:=cs.Create(); // 这里就数组越界了
muserinfo[i].fhz:='1'; // 这里就数组越界了
end;
i:=getsz(muserinfo);
showmessage(string(i));
后面的function getsz(sz:szcs):integer ;也有同样的问题,而且没有SetLength,muserinfo是空数组。
窗口的对象代码:
cs=class
private
fhz:WideString;
cz:WideString;
published
property Ffhz: WideString read fhz write fhz;
property Fcz: WideString read cz write cz;
end;
szcs=array of cs;
加了个按钮,代码:
function getsz(sz:szcs):integer ; stdcall; external 'tkrsdll.dll';
procedure TForm1.Button1Click(Sender: TObject);
var
muserinfo:szcs;
i:integer;
begin
SetLength(muserinfo,1);
for i:=1 to 1 do
begin
muserinfo[i]:=cs.Create();
muserinfo[i].fhz:='1';
end;
i:=getsz(muserinfo);
showmessage(string(i));
tkrsdll.dll这个DLL对象的getsz方法:
function getsz(sz:szcs):integer ; stdcall;
var
muserinfo:szcs;
i:integer;
begin
for i:=1 to 1do
begin
muserinfo[i]:=cs.Create();
muserinfo[i].fhz:='1';
end;
result:=integer(muserinfo[1].fhz);
end;
exports getsz;
然后运行窗口点击按钮的时候,就报错了,“Project szcss.exe raised excepton calss EAccessVilation with message 'Access violation at address 03D2358 in module ''tkrsdll.dll'”,
在哪里出问题了呢?
------解决思路----------------------
因为 szcs=array of cs; 这是一个动态数组类型,动态数组的下标要求是整数,而且从0开始,与静态数组不同。
所以你
function getsz(sz:szcs):integer ; stdcall; external 'tkrsdll.dll';
procedure TForm1.Button1Click(Sender: TObject);
var
muserinfo:szcs;
i:integer;
begin
SetLength(muserinfo,1);
for i:=1 to 1 do
begin
muserinfo[i]:=cs.Create(); // 这里就数组越界了
muserinfo[i].fhz:='1'; // 这里就数组越界了
end;
i:=getsz(muserinfo);
showmessage(string(i));
后面的function getsz(sz:szcs):integer ;也有同样的问题,而且没有SetLength,muserinfo是空数组。