请问一下,一个函数返回值是动态数组,如何分配这个函数的地址啊。
type
  TMyArray =  array of array of string ;
  TForm_fbt = class(TForm)
...
public
    function setbg(sl:Tstringlist):TmyArray;function Tform_fbt.setbg(sl:Tstringlist):TmyArray;
var Ttemparray: TmyArray;
    i,j,k,k1,k2,k3,k4:integer;
    a:array[0..9] of integer;
    sl1,sl2,sl3:Tstringlist;
    str:string;
begin
  setlength(Ttemparray,sl.Count+1,160);
  .... 
  result:= Ttemparray;end;然后我调用数组函数high(setbg(sl1)) 这样就报错了。最后返回结果时报错。是什么原因啊?

解决方案 »

  1.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, ComCtrls;type
      TMyArray = array of array of string ;
      TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
        function setbg(sl:Tstringlist):TmyArray;
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}{ TForm1 }function TForm1.setbg(sl: Tstringlist): TmyArray;
    var
      Ttemparray: TmyArray;
      i,j,k,k1,k2,k3,k4:integer;
      a:array[0..9] of integer;
      sl1,sl2,sl3:Tstringlist;
      str:string;
    begin
      setlength(Ttemparray,sl.Count+1,160);
      Result:=Ttemparray;
    end;procedure TForm1.Button1Click(Sender: TObject);
    var
      strList:Tstringlist;
    begin
      strList:= Tstringlist.Create;
      strList.Add( '123' );
      strList.Add( '123' );
      strList.Add( '123' );
      showmessage( IntToStr( high(setbg(strList)) ) );
    end;end.
    --执行结果---------------------------
    Project1
    ---------------------------
    3
    ---------------------------
    OK   
    ---------------------------
      

  2.   

    不可能是这个问题setlength(Ttemparray,sl.Count+1,160);
    ....//这部分代码会不会有问题?
    result:= Ttemparray;
      

  3.   

    解决了,函数内部有点问题。超出范围了。NND,我自己不小心。浪费大家时间了。