Sign in Join

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

Mailing lists / fpc-pascal / 2011-05

FillWord with dynamics array.

3 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

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

Luis Fernando Del Aguila Mejía

How fill of the same value a dynamic array?

{$codepage utf8}
Var A,B:array of word;
       i:integer;
Begin
   SetLength(A,10);
   SetLength(B,10);
   FillWord(A[0],2*10,0);  //when value diferent to zero, no runtime error
   FillWord(B[0],2*10,0);
   for i:=0 to 9 do Writeln(i,A[i]:3,B[i]:3);
End.

thanks.

Reply by email

Jonas Maebe
to Luis Fernando Del Aguila Mejía
Luis Fernando Del Aguila Mejía wrote 10 lines
How fill of the same value a dynamic array? {$codepage utf8} Var A,B:array of word; i:integer; Begin SetLength(A,10); SetLength(B,10); FillWord(A[0],2*10,0); //when value diferent to zero, no runtime error

FillWord fills per word (= 16 bit). So you are filling 2*10 = 20 words, while you only allocated 10. Use fillchar if you want to specify the number of bytes.

Jonas

Reply by email

Luis Fernando Del Aguila Mejía
to Jonas Maebe

Thanks. Gracias.

Jonas Maebe wrote 17 lines
On 26 May 2011, at 23:18, Luis Fernando Del Aguila Mejía wrote: > How fill of the same value a dynamic array? > > {$codepage utf8} > Var A,B:array of word; > i:integer; > Begin > SetLength(A,10); > SetLength(B,10); > > FillWord(A[0],2*10,0); //when value diferent to zero, no runtime error FillWord fills per word (= 16 bit). So you are filling 2*10 = 20 words, while you only allocated 10. Use fillchar if you want to specify the number of bytes. Jonas

Reply by email