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:=Random(100);
Memo1.Lines.Add(FloatToStr(sz));
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));
end;
finally
FreeLibrary(onehandle);
end;
end;
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
无标题.png (8.82 KB, 下载次数: 235)
implicit none
implicit a-h,o-z
欢迎光临 Fortran Coder (http://bbs.fcode.cn/) | Powered by Discuz! X3.2 |