16,748
社区成员
发帖
与我相关
我的任务
分享
library GenRandoms;
{$R *.res}
function GetRandoms( const Out_Random_Arr: PIntegerArray (*目标地址,请在主调用程序分配足够的内存*)
; const In_Random_Count: Word (*随机数个数*)
): Boolean; stdcall;
var
I: Integer;
begin
for I := 0 to In_Random_Count - 1 do
begin
Out_Random_Arr[I] := Random(10000);
end;
Result := true;
end;
exports
GetRandoms;
begin
end.
unit uTestMain;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm2 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
function GetRandoms( const Out_Random_Arr: PIntegerArray (*目标地址,请在主调用程序分配足够的内存*)
; const In_Random_Count: Word (*随机数个数*)
): Boolean; stdcall;external 'GenRandoms.dll';
implementation
{$R *.dfm}
procedure TForm2.Button1Click(Sender: TObject);
var
Rnds: PIntegerArray;
iCount: Integer;
I: Integer;
begin
iCount := 10;
GetMem(Rnds,iCount * sizeof(Integer));
fillchar( PAnsiChar(Rnds)^,iCount * sizeof(Integer),0);
GetRandoms(Rnds,iCount);
for I := 0 to iCount - 1 do
ShowMessage(IntToStr(Rnds[i]));
end;
end.