Передача массива в/из DLL
Передача массива в/из DLL
Передача массива в/из DLL library Project1; {$R *.res} uses Types; type PSingleDynArray = ^TSingleDynArray; TSingleDynArray = array of Real; TDoubleDynArray = array of array of Real; function Test(const InValue: TDoubleDynArray; const ArrayLength: TSize; var OutValue: TSingleDynArray): Boolean; stdcall; var Count, X, Y: Integer; Ser: Real; AOutValue: TSingleDynArray; begin Result := True; try Count := 0; Ser := 0; for X := 0 to ArrayLength.cx - 2 do for Y := 0 to ArrayLength.cy - 2 do begin Ser := Ser + InValue[X, Y]; Inc(Count); end; Ser := Ser / Count; for X := 0 to ArrayLength.cx - 2 do OutValue[X]:=(Ser - Abs(InValue[X, Trunc(ArrayLength.cx / 2)])); except Result := False; end; end; exports Test; begin end. unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); end; var Form1: TForm1; implementation type PSingleDynArray = ^TSingleDynArray; TSingleDynArray = array of Real; TDoubleDynArray = array of array of Real; function Test(const InValue: TDoubleDynArray; const ArrayLength: TSize; var OutValue: TSingleDynArray): Boolean; stdcall; external 'project1.dll'; {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); var X, Y: Integer; InArray: TDoubleDynArray; InSize: TSize; OutArray: TSingleDynArray; begin Randomize; InSize.cx := 20; InSize.cy := 20; SetLength(InArray, InSize.cx, InSize.cy); for X := 0 to InSize.cx - 1 do for Y := 0 to InSize.cy - 1 do InArray[X, Y] := Random(100); SetLength(OutArray, InSize.cx); if Test(InArray, InSize, OutArray) then // тут работаем с массивом end; end.