Delphi and Kylix

Moderators: pritaeas
Number of threads: 7264
Number of posts: 19073

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Slice function in Delphi 8 Posted by kruti kansara on 12 Feb 2005 at 12:41 AM
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.



Report
Re: Slice function in Delphi 8 Posted by zibadian on 14 Feb 2005 at 4:13 AM
: 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.
Report
Re: Slice function in Delphi 8 Posted by kgraphics on 14 Feb 2005 at 9:31 PM
: : 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.




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.