I have a problem in pass a dynamic array in Delphi to a Fortran DLL.
And there is a access violation problem
I think there is something wrong about the pointer, but I am not familiar
with it.
-----Here is my delphi code------
implementation
function dnyarray(var dnya:array of integer;var max:integer):integer;
stdcall;
external '4.dll';
procedure TForm1.BitBtn1Click(Sender: TObject);
var i:integer;
var dnya:array of integer;
begin
i:=15;
setlength(dnya,i);
for i:=0 to 14
do dnya[i]:=1;
k:=dnyarray(dnya,i);
end;
-----Following is the Fortran DLL-------
function dnyarray(dnya,vbmax)
!DEC$ ATTRIBUTES DLLEXPORT, alias:'dnyarray' ::dnyarray
integer,pointer :: dnya(:)
vvvb(vbmax-1)=123
dnyarray=vvvb(vbmax-1)
end function
Thanks !!
Lee
DON'T use assumed-shape or pointer arrays when doing mixed-language.
Fortran pointers are not just addresses -- they are actually structured
array descriptors, which are tough to mimic in other
languages. (IIRC CVF descriptor for an one-dimensional array
is a structure of 28 bytes, passed by reference -- but that's
not portable even accross Fortran compilers)
If you use assumed-size array instead you should be fine:
integer:: dnya(*)
If the length of the array is necessary, you can pass it as an
additional argument.
--
Jugoslav
___________
www.geocities.com/jdujic
The best advice has already been given - don't use dynamic arrays in
mixed language programming. Keep it simple and use assumed size arrays
on the fortran side.
Avoid assumed shape arrays on the fortran side: these require extra
parameters on the Delphi side in order to say things about maximum
subscript value and stride.
In message <angs4r$e29pg$1...@ID-106075.news.dfncis.de>, Jugoslav Dujic
<jdujic...@uns.ns.ac.yu> writes
--
John Mansell jo...@wcompsys.co.uk