I am trying to get familar with freepascal basic concepts,now I am stuck with the pointer to array (both static and dynamic).
Please see below full code which can be compiled.My questions are as shown in the comments.
For
1: This
is the correct way to do this conversion, however the
NativeUInt type is declared an an alias to the corresponding base type of the correct size for a pointer and thus for the compiler this type is in no way special and thus it needs to warn, because the pointer size might be different on a different platform. There is no built-in type that automatically matches the size of a pointer and thus there is no way to circumvent the compiler's message here.
For
2: The difference between a static array and a dynamic array is that a dynamic array variable itself already
is a pointer. So for a static array a pointer to the first element of the array and to the variable itself is the same, but for a dynamic array a pointer to the first element of the array is
different from a pointer to the variable. So you need to do another dereferenciation or better yet: don't use pointers with dynamic arrays at all.
For
3: This immediately follows the explanation for
2: a pointer to a dynamic array is a pointer to a dynamic array and
not a pointer to the first element and thus you can't assign that to a
PByte in your specific case.