: : Hi all,
: :
: : I am learning Delphi 8. I am getting an error on using 'Slice' function.
: : "[Error] Unit1.pas(47): Slice standard function only allowed as open array argument"
: : The same code execute successfuly in Delphi 6. Code is as,
: :
: : var
: : SliceMe : array [1..200] OF Integer;
: :
: : procedure TakesArray(x : array of Integer);
: : var
: : str : String;
: : cnt : Integer;
: : begin
: : str := '';
: : for cnt := 0 to 24 do str := str+inttostr(x[cnt])+',';
: : showmessage(str);
: : end;
: :
: : procedure TForm1.Button1Click(Sender: TObject);
: : var
: : cnt : Integer;
: : begin
: : for cnt := 0 to 199 do SliceMe[cnt]:=cnt;
: : cnt := 0;
: : while cnt<200 do begin
: : TakesArray(Slice(SliceMe,25));
: : inc(cnt,25);
: : end;
: : end;
: :
: : Can anybody help me reagarding this? Is there any unit i have to add in Delphi 8?
: :
: : Thanks in advance.
: :
: : Kruti.
: :
: :
: :
: :
: You could try to use a temporary array variable, which holds only the subarray:
:
: procedure TForm1.Button1Click(Sender: TObject);
: var
: cnt : Integer;
: IntArray: array of integer;
: begin
: for cnt := 0 to 199 do SliceMe[cnt]:=cnt;
: cnt := 0;
: while cnt<200 do begin
: IntArray := Slice(SliceMe,25);
: TakesArray(IntArray);
: inc(cnt,25);
: end;
: end;
:
: Another possibility is that Slice() can only take open arrays as parameters. In that case you should define SliceMe as an open array, and use SetLength() to (de)allocate it.
:
hi,
I do the same as u described. But it still giving me the same error on line,
IntArray := Slice(SliceMe,25);
Also, i already checked the second option by defining SliceMe as an open array, but it doesnt make any mean.
Thnx & Rgds,
Kruti.