Q:  How do I use arrays in a Delphi DLL with VB?  (from a compuserve post)

I'm trying to get a DLL written in Delphi (TESTDLL.DLL) to reference an array created in Visual Basic.  When I run it, I get a GPF in TESTDLL.DLL.

Code in VB is:

' Start of VB Code ****************************************
' Form level declarations
Declare Function ReadArray Lib "TestDLL.dll" (TestArr As Any) As Integer
Dim TestArray(3) As Integer  ' Declares an array[0..3] of integer in VB

Sub Form_Load

  TestArray(0) = 2
  TestArray(1) = 4
  TestArray(2) = 6
  TestArray(3) = 8

End Sub
 
Sub cmdDelphi_Click ()
Dim iResult As Integer

  iResult = ReadArray(TestArray(0))  ' Documentation says this is the way to get VB to
                                     ' pass a pointer to an array
  MsgBox "Back once again with result = " & iResult

End Sub
' End of VB Code  ********************************************

Code in Delphi is:
{Start of Delphi Code ****************************************}
interface
.
.

function ReadArray(var TestArray: array of integer): integer; export;
.
.

implementation

function ReadArray(var TestArray: array of integer): integer;
var
  iCount : integer;
begin

  for iCount := 0 to 3 do
  begin
    ShowMessage( 'Element ' + InttoStr(iCount) + ' = ' + IntToStr(TestArray[iCount]));
  end;
  Result := 4;
end;
{End of Delphi Code ****************************************}