将记录数组传递给delphi dll

时间:2012-03-14 07:44:00

标签: arrays delphi dll record

是否可以将记录数组传递给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;

1 个答案:

答案 0 :(得分:0)

将大量数据传递给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);
...
相关问题