Can someone explain why it makes no difference between using Larr and Larr1 but makes a difference between LBytes[0] and LBytes?
That's because LBytes
is a dynamic array which is, ultimately, a pointer to the array. On the other hand, LArr
is the array.
Another way to say this is that dynamic arrays are reference types, and fixed length arrays are value types.
In my book, there are two viable ways to do this:
Assert(Length(LBytes)<=Length(LArr));
Move(LBytes[0], LArr, Length(LBytes));
or
Assert(Length(LBytes)<=Length(LArr));
Move(Pointer(LBytes)^, LArr, Length(LBytes));
I prefer the latter, because it is resilient to a zero length array when range checking is enabled. In that scenario, the first block of code leads to a run time range check error.
You might also be motivated to avoid such low-level trickery. I have a utility class that allows me to write:
TArray.Move<Byte>(LBytes, LArr);
The signature of the method is:
class procedure Move<T>(const Source: array of T; var Dest: array of T); overload; static;