你把initarray定义成function把数值用返回的形式,试试看!

解决方案 »

  1.   

    procedure TForm1.InitArray(var TheArray:Array of integer);
    看看?
      

  2.   

    谢谢各位,问题正如 windindance(风舞轻扬) 所言
      

  3.   

    可否再帮我看看
    http://www.csdn.net/expert/topic/608/608473.xml?temp=.9074518
      

  4.   

    unit Unit166;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, ExtCtrls;type
     TSortArray=array [0..10] of Integer;//注意这儿
        TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
        procedure InitArray(TheArray:TSortArray);//还有这儿
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}var
     BubArray:TSortArray;
    procedure TForm1.InitArray(TheArray:TSortArray);//这儿也一样
      var
       I:Integer;
       S:String;
      begin
        Randomize;
        for I:=0 to High(TheArray) do
          begin
          TheArray[I]:= Random(170);
          S:=S+IntToStr(TheArray[I])+','  ;
          end;
        ShowMessage(S);//此处显示正常,数组所有单元都初始化有值
      end;
    procedure TForm1.Button1Click(Sender: TObject);
    var
     I:Integer;
     S:String;
    begin
      InitArray(BubArray);
      for I:=0 to high(BubArray) do
        S:=S+IntToStr(BubArray[I])+','  ;
      ShowMessage(S);  //此处显示数组所有值全为0
    end;
    end.
    现在你看看吧
      

  5.   

    unit Unit166;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, ExtCtrls;type
        TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
        procedure InitArray();//还有这儿
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}type TSortArray=array [0..10] of Integer;
    var
     BubArray:TSortArray;
    procedure TForm1.InitArray();//这儿也一样
      var
       I:Integer;
       S:String;
      begin
        Randomize;
        for I:=0 to High(BubArray) do
          begin
          BubArray[I]:= Random(170);
          S:=S+IntToStr(BubArray[I])+','  ;
          end;
        ShowMessage(S);//此处显示正常,数组所有单元都初始化有值
      end;
    procedure TForm1.Button1Click(Sender: TObject);
    var
     I:Integer;
     S:String;
    begin
      InitArray();
      for I:=0 to high(BubArray) do
        S:=S+IntToStr(BubArray[I])+','  ;
      ShowMessage(S);  //此处显示数组所有值全为0
    end;
    end.