Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2008-01

Copying array raising exception

2 messages · 1 person · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Joao Morais

Hello,

The following code:

var
   s1, s2: string;
   v1, v2: array of byte;
begin
   writeln('testing strings');
   s1 := 'test';
   s2 := copy(s1, 2, 10);
   writeln('s2: "', s2, '" which length is ', length(s2));
   s2 := copy(s1, 10, 10);
   writeln('s2: "', s2, '" which length is ', length(s2));
   writeln('now testing dynamic array');
   setlength(v1, 5);
   v2 := copy(v1, 2, 10);
   writeln('length is: ', length(v2));
   v2 := copy(v1, 6, 10);         //  <<-- here
   writeln('length is: ', length(v2));
end.

will raise an exception, range check error iirc, trying to copy an array beyond the number of its items. Just to know if this was designed or I should report to mantis.

Thanks.

Joao Morais ps - Michael, now my Format function rocks =)
Joao Morais
to Joao Morais
Joao Morais wrote 11 lines
writeln('now testing dynamic array'); setlength(v1, 5); v2 := copy(v1, 2, 10); writeln('length is: ', length(v2)); v2 := copy(v1, 6, 10); // <<-- here writeln('length is: ', length(v2)); end. will raise an exception, range check error iirc, trying to copy an array beyond the number of its items. Just to know if this was designed or I should report to mantis.

Remember.

FYI I can survive with this behavior, it was reported because it isn't consistent with Delphi.

Joao Morais