System: Windows
Compiler/IDE: Lazarus & Delphi (trying multiplatform)
libraries: RTL
I'm using a DLL written in C. This library has several functions that use arrays. C uses pointers in most cases so I did something like this:[pascal]PROGRAM example;
TYPE
TLISTptr = ^TLIST;
TLIST = RECORD
Field: INTEGER;
Other: INTEGER;
END;
FUNCTION get_list: TLISTptr; CDECL; EXTERNAL 'lib.dll';
VAR
TheList: TLISTptr;
BEGIN
{ Somewhere }
TheList := get_list;
WriteLn (TheList[0]);
END.[/pascal]That compiles and runs perfect using Free Pascal but some users tells me that Delphi can't compile it. So I changed it by this:[pascal]PROGRAM example;
TYPE
TLIST_ITEMptr = ^TLIST_ITEM;
TLIST_ITEM = RECORD
Field: INTEGER;
Other: INTEGER;
END;
TLISTptr = ^TLIST;
TLIST = ARRAY OF TLIST_ITEM;
FUNCTION get_list: TLISTptr; CDECL; EXTERNAL 'lib.dll';
VAR
TheList: TLISTptr;
BEGIN
{ Somewhere }
TheList := get_list;
WriteLn (TheList^[0]);
END.[/pascal]Free Pascal compiles it but it returns a runtime 216 error. No idea about Delphi.
By the way this code seems to work both Delphi and FPC:[pascal]PROGRAM example;
TYPE
TLIST_ITEMptr = ^TLIST_ITEM;
TLIST_ITEM = RECORD
Field: INTEGER;
Other: INTEGER;
END;
TLISTptr = ^TLIST;
TLIST = ARRAY [0..80] OF TLIST_ITEM;
FUNCTION get_list: TLISTptr; CDECL; EXTERNAL 'lib.dll';
VAR
TheList: TLISTptr;
BEGIN
{ Somewhere }
TheList := get_list;
WriteLn (TheList^[0]);
END.[/pascal]But the returned list size may vary from 1 to infinite, so this isn't the solution
¬øAlny idea about how to work with a non-sized array pointer in Delphi?
Thanks
Bookmarks