请问大家声明函数时,返回数据为数组类型,如何定义;
function ArrayRandom():array [0..35] of integer;//这个有错

解决方案 »

  1.   

    先声明一个类型
    TMyArr=array [0..35] of integer;function farrary:TMyArr;
      

  2.   

    给一个示例程序吧:
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls;type
    TMyArr=array [0..35] of integer;
      TForm1 = class(TForm)
        Button1: TButton;
        ListBox1: TListBox;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;function farrary:TMyArr;
    implementation{$R *.DFM}
    function farrary:TMyArr;
    var
      jsq:integer;
    begin
    for jsq:=0 to 35 do
    begin
    randomize;
    result[0]:=random(100);
    end;
    end;procedure TForm1.Button1Click(Sender: TObject);
    Var
      rt:TMyArr;
      jsq:integer;
    begin
    rt:=farrary;
    for jsq:=0 to 35 do
    listbox1.Items.Add(inttostr(rt[jsq]));
    end;end.
      

  3.   

    //对不起,改为这样比较好unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls;type
    TMyArr=array [0..35] of integer;
      TForm1 = class(TForm)
        Button1: TButton;
        ListBox1: TListBox;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;function farrary:TMyArr;
    implementation{$R *.DFM}
    function farrary:TMyArr;
    var
      jsq:integer;
    begin
    randomize;
    for jsq:=0 to 35 do
    begin
    result[jsq]:=random(100);
    end;
    end;procedure TForm1.Button1Click(Sender: TObject);
    Var
      rt:TMyArr;
      jsq:integer;
    begin
    rt:=farrary;
    listbox1.Clear;
    for jsq:=0 to 35 do
    listbox1.Items.Add(inttostr(rt[jsq]));
    end;end.