搞了很久才搞清楚如何二者混编,先上代码
Delphi中的:
[Delphi] 纯文本查看 复制代码
type
Tvar=function(a:integer;b:array of real):real;stdcall;
procedure TForm1.Button1Click(Sender: TObject);
var shuzu:TFarProc;
onehandle:THandle;
myf:Tvar;
sz:array of Real;
i:Integer;
begin
SetLength(sz,StrToInt(Edit2.Text));
for I := Low(sz) to High(sz) do
begin
sz[i]:=Random(100);
Memo1.Lines.Add(FloatToStr(sz[i]));
end;
onehandle:=LoadLibrary('D:\TestDll.dll');
try
if onehandle <> 0 then
begin
shuzu:=GetProcAddress(onehandle,'Sortandfindmax');
end;
if shuzu <> nil then
begin
myf:=tvar(shuzu);
Edit1.Text:=FloatToStr(myf(Length(sz),sz));
for I := Low(sz) to High(sz) do
Memo2.Lines.Add(FloatToStr(sz[i]));
end;
finally
FreeLibrary(onehandle);
end;
end;
Fortran中的
[Fortran] 纯文本查看 复制代码 FUNCTION SORTANDFINDMAX(LENGTH,ARRAY)
!------------------------------如果将变量的顺序调换为 ARRAY,LENGTH,那么就出现传输数组时数组长度少一位
!DEC$ ATTRIBUTES DLLEXPORT::SORTANDFINDMAX
!DEC$ ATTRIBUTES STDCALL,ALIAS:'Sortandfindmax'::SORTANDFINDMAX
DOUBLE PRECISION ::ARRAY(LENGTH)
INTEGER::I,J
DOUBLE PRECISION::SORTANDFINDMAX,TEMP
SORTANDFINDMAX=ARRAY(1)
DO I=1,LENGTH-1
DO J=I+1,LENGTH
IF(ARRAY(I).GT.ARRAY(J)) THEN
TEMP=ARRAY(I)
ARRAY(I)=ARRAY(J)
ARRAY(J)=TEMP 不讨论算法效率
SORTANDFINDMAX=ARRAY(J)
END IF
END DO
END DO
END
哪位给指点一下,为什么需要将数组放在最后呢 |