procedure Test(var arrInt: TArray<Integer>); stdcall; const Count = 23; var I: Integer; begin SetLength(arrInt, Count); for I := 0 to Count - 1 do begin arrInt[I] := I + 1; end; end;
procedure Test(var p: Pointer; var size: Integer); stdcall; const Count = 23; var I : Integer; ttt: array of Integer; begin SetLength(ttt, Count); for I := 0 to Count - 1 do begin ttt[I] := I; end;
RAD 11 ALEXANDRIA -> EXE x32bits, MSWin 10 x64 for tests
library ArrayInDLL;
IMPORTANT! IMPORTANT! IMPORTANT! ---> SHAREMEM or similar...
{ Important note about DLL memory management: ShareMem must be the first unit in your library's USES clause AND your project's (select Project-View Source) USES clause if your DLL exports any procedures or functions that pass strings as parameters or function results. This applies to all strings passed to and from your DLL--even those that are nested in records and classes. ShareMem is the interface unit to the BORLNDMM.DLL shared memory manager, which must be deployed along with your DLL. To avoid using BORLNDMM.DLL, pass string information using PChar or ShortString parameters. }
function ExportMyArray(AHowManyElements: integer): TMyArrayToResult; stdcall; begin result := []; // if AHowManyElements > 1000 then { just for test }; // for var i: integer := 1 to AHowManyElements do result := result + [i]; end;
procedure TForm1.Button1Click(Sender: TObject); var MyResult: TMyArrayToResult; begin MyResult := ExportMyArray(395); // // for var MyItem in ExportMyArray(395) do // for var MyItem in MyResult do Memo1.Lines.Add(MyItem.ToString);
end;
end.
此帖子包含附件: 大小:6.5K
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
GetMem allocates a block of the given Size on the heap, and returns the address of this memory in the P parameter. The bytes of the allocated buffer are not set to zero. To dispose of the buffer, use FreeMem. If there is not enough memory available to allocate the block, an EOutOfMemory exception is raised.
my note: try ... except ... end;
Note: If the memory block must be initialized with zero, you can use AllocMem.
This function is not available in C++. In C++ you can use GetMemory.
In case of a typed pointer, you should consider the New and Dispose procedures, which respectively initialize and finalize the memory block accordingly.
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
As said some article Embarcadero, FastMM (lite version no-sources) is used for now.
But, "borlandmm" still as compatibility with old IDE(s) of course and help in any moment necessary :)
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3