我想在dll里定义一个函数,而这个函数有多个返回值  函数的定义该怎么写?
这样写大家看看为什么不能用:
var
  a  :array[1..10] of real;
function allowance(B: array[1..10] of Real):a;
begin
end;
我是个新手,愿大家指教的时候,尽量解释得详细些,有例子最好。谢谢大家了!

解决方案 »

  1.   

    我将定义改成:
    function aa(b:array of Real ):array[1..3] of Real ;
    不能编译,报错:Identifier expected but ‘array’ found 和 Array type required
      

  2.   

    如果是有限个,则定义多个参数,否则就定义一个指针加一个用于指示指针所指向的参具体的个数。或者使用结构体等。
    function GetArray(Command: Integer(*指令*); var Param0(*第一个返回参数*), Param1(*第二个返回参数*), Param2(*第三个返回参数*): Real): Boolean; stdcall; 
      

  3.   

    DLL源代码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;interfaceuses
      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.
      

  4.   

    GetMem之后,记得FreeMem,测试程序,我就没写了。