procedure SetLength(var S; NewLength: Integer);

解决方案 »

  1.   

    我用了SetLength(myArray, 20);
    错误提示:
    [Error] main.pas(40): Incompatible types
      

  2.   

    TDM , 还是不行,
      VararrayCreate!!!
      

  3.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
         myArray : array of string;
         i:integer;
    begin
         SetLength(myArray,20);
         for i:=0 to 19 do
           myArray[i]:='aaa';
    end;以上程序,经过测试没问题。  再搞不掂,把你的代码贴上来。然后自打两下屁股
      

  4.   

    ChinaDelphiFan()
    对不起,我的用法不是你那样的!楼上的代码一定可以的。
    ===========================================================
    procedure my(Astr : string ;var spltstr:array of string ) ;
    var
      mystr : string ;
      i,j  : integer ;
      myarr : array of string ;
    begin
      mystr := Astr ;
      j := 0 ;
      for i := 1 to length(mystr) do
      begin
        if mystr[i]=',' then
        j := j + 1 ;
      end;
      setlength(myarr,j) ;
      //setlength(spltstr,j) ;  直接使用时,此时就出错了  j := 0 ;
      for i := 1 to length(mystr) do
      begin
        if mystr[i]=',' then
        j := j + 1
        else
        myarr[j] := myarr[j]+mystr[i] ;
      end;
      
      spltstr := myarr ; //TMDTMD!!!~~~~~~~~~~^OO^~~~~~~~~~~~~~~~~
    end;
      

  5.   

    delphi帮助中的一段话,仔细读读,你就可以解决了。
    ------------------------------------------
    Within the body of a routine, open array parameters are governed by the following rules.They are always zero-based. The first element is 0, the second element is 1, and so forth. The standard Low and High functions return 0 and Length ?1, respectively. The SizeOf function returns the size of the actual array passed to the routine.
    They can be accessed by element only. Assignments to an entire open array parameter are not allowed.
    They can be passed to other procedures and functions only as open array parameters or untyped var parameters. They cannot be passed to SetLength.Instead of an array, you can pass a variable of the open array parameter抯 base type. It will be treated as an array of length 1.
      

  6.   

    定义 Tmyarray = array of string;
    再把代码改成:
    procedure my(Astr : string ;var spltstr:Tmyarray);
    你再试试,应该可以。
    好像是delphi的特性
      

  7.   

    redwoodnymph(红蜂鸟)
      这样子的确可以了,但是
      Tmyarray 类型的数组,在使用中不知道如何做了
        如 :
       var
       myarr : Tmyarray ;
       str : string ;
       i : integer ;
       begin
         my(str,myarr) ;
         for i:=low(myarr) to high(myarr) do //此时出错了
       .............
        end ;
          
      

  8.   

    有没有搞错,用StringList嘛
    本来就是动态的string类型数组。
      

  9.   

    设置数组嘛!
    var 
    myarray:array[0..34] of string
      

  10.   

    begin
        my(str,myarr) ;
        for i:=low(myarr) to high(myarr) do //此时出错了
      .............
        end ;
    myarr没分配空间