[fpc-pascal] problem with array of string

Eduardo Morras nec556 at retena.com
Tue Dec 21 19:36:13 CET 2004


At 22:15 20/12/2004, you wrote:
>I have problem with two dimension array of string
>
>my program:
>
>procedure testlinie;
>var
>    linie  : array[0..1,0..100] of shortstring;
>    i,ii : integer;
>begin
>   fillchar(linie,sizeof(linie),0);
>   for i := 0 to 1 do begin
>     for ii:= 1 to 10 do begin
>       linie[i,ii]:= linie[i,ii]+char(64+ii);
>       writeln(i:5,ii:5,linie[i,ii]) ;
>
>     end;
>   end;
>end;
>
>during execution output is:
>0 1 A
>0 2 B
>0 3 C etc.
>
>but should be:
>0 1 A
>0 2 AB
>0 3  ABC
>
>on Delphi all works OK.

On delphi it works exactly the same. Your code never do what you want, only 
what it can do. The problem is that you have a matrix (2,101) with strings. 
If you do

linie[i,ii]:= linie[i,ii]+char(64+ii); (i=0; ii=0) ->   linie[0,0]:= 
linie[0,0]+'A'
linie[i,ii]:= linie[i,ii]+char(64+ii); (i=0; ii=1) ->   linie[0,1]:= 
linie[0,1]+'B'
linie[i,ii]:= linie[i,ii]+char(64+ii); (i=0; ii=2) ->   linie[0,2]:= 
linie[0,2]+'C'


so on each inner cycle you are adding a letter to other string in the 
matrix. The linie structure is in fact a tridimensional matrix 
[0..1,0..100,0..sizeof(shortstring)] of char . It's not a bug in the 
compiler, only in your code.

HTH


-------------------------------------------------------------------------------------------------------------------------------------------------------------------
Scientists have shown that the moon is moving away at a tiny yet measurable 
distance from the earth every year.
  If you do the math, you can calculate that 85 million years ago the moon 
was orbiting the earth at a distance of
  about 35 feet from the earth's surface. This would explain the death of 
the dinosaurs. The tallest ones, anyway. 





More information about the fpc-pascal mailing list