2012-03-14 43 views
2

是否有可能傳遞一個數組的記錄到DLL(德爾福)?傳遞數組的記錄到德爾福DLL

我有把在記錄中的共享的Delphi單元

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

TarrOfMyRecord = array[1..1000] of TmyRecord 

在DLL(在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; 

我不能t獲取由dll返回的someRecord的正確值。

感謝

UPDATE: 這是我主要的應用程序代碼:

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; 
+0

顯示調用該DLL的代碼。另外,你是否知道你當前的方法提交了用Delphi編寫的DLL的所有用戶?你對此感到滿意嗎? – 2012-03-14 07:47:21

+0

@DavidHeffernan:是的,我知道這件事,那沒關係。 – abanas 2012-03-14 08:17:44

+0

您的函數定義爲getNotes(var someRecord:TArrOfMyRecord),但您傳遞變量myRecord:TmyRecord?這是一個錯字嗎? – Justmade 2012-03-14 08:22:01

回答

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); 
... 
+0

這樣我就可以使用一個唯一的Delphi應用程序,或者我用其他語言調用DLL? – Martin 2012-12-20 13:30:34

+0

@Martin這種方法可以用於任何由任何編程語言編寫的程序。一些Windows API函數也使用這種方法。 – Vahid 2012-12-21 15:59:47

+0

如果我嘗試使用你的代碼,我會在「if getNotes(@myRecord)」上得到一個錯誤,因爲「函數必須有一些參數」...... – Martin 2012-12-21 22:35:49