gpt4 book ai didi

arrays - 将记录数组传递给delphi dll

转载 作者:行者123 更新时间:2023-12-03 18:50:22 25 4
gpt4 key购买 nike

是否可以将记录数组传递给dll(delphi)?

我有一条记录放在共享的(用于dll和主应用程序)delphi单元中

TmyRecord = record
tgl : Double;
notes: shortstring;
end

TarrOfMyRecord = array[1..1000] of TmyRecord


在dll中,我有一个功能:

function getNotes(var someRecord: TArrOfMyRecord):boolean; stdcall;
begin
someRecord[1].tgl:= now;
someRecord[1].notes:= 'percobaan';

someRecord[2].tgl:= now + 1;
someRecord[2].notes:= 'percobaan1';

return:= true;
end;


我无法获得dll返回的someRecord的正确值。

谢谢

更新:
这是我在主要应用程序中的代码:

interface

function getNotes(var someRecord: TArrOfMyRecord):boolean; stdcall; external 'some.dll'

implementation

procedure somefunction;
var myRecord: TarrOfMyRecord;
i: integer;
begin
if getNotes(myRecord) then
for i:= 1 to 1000 do memo1.lines.add(myRecord[i].notes);

end;

最佳答案

将大量数据传递到DLL的最佳方法是使用指针。

记录定义:

...
TarrOfMyRecord = array[1..1000] of TmyRecord
ParrOfMyRecord = ^TarrOfMyRecord;


DLL:

function getNotes(someRecord: PArrOfMyRecord):boolean; stdcall;
begin
someRecord^[1].tgl:= now;
...


程序:

...
begin
if getNotes(@myRecord) then
for i:= 1 to 1000 do memo1.lines.add(myRecord[i].notes);
...

关于arrays - 将记录数组传递给delphi dll,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9697731/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com