Talk:Dynamic array

From Lazarus wiki
Revision as of 11:39, 11 August 2014 by Ruediger (talk | contribs)
Jump to navigationJump to search

I was a little bit confused about the sentence "To init such an invalid pointer you have to use FillChar(MyVariable,sizeof(MyVariable), #0)." This might be misleading, as this fills the pointer to MyVariable with the size of this pointer with zeros, not the array itself, as far as I understand. This might be different to static arrays (didn't prove that). Logically, the sentence is right. But it's anyway confusing, because the instruction does not do, what it seems to do in human language: FillChar doesn't fill My(Array)Variable, and SizeOf doesn't return the size of MyVariable...

It took me some time to understand this. Then it's not very hard to find out, how to initialize the array itself:

 FillChar(MyVariable[0], Length(MyVariable) * SizeOf(TheArrayType), #0);

So the problem is mainly the terminology, which puts you in the wrong trace. Perhaps this difference between initializing the array itself and the reference to the array should be emphasized? Or did I misunderstand something there?