If I wanted to declare a static byte compilation time array, I could do it like this:
var bytes :array[0..24] of Byte = (1, 2, 3, .... );
However, the type of this array is [0..24] bytes, not System.TArray<System.Byte> , which is better known as TBytes .
I need something like TBytes, but I don't want to add an initialization section to hold these byte values ββin some painful way:
var bytes2:TBytes; initialization SetLength(bytes2,24); bytes2[0] := 1; bytes2[1] := 2; ....
Is there a way to do this instead:
var bytes2:TBytes = (1,2,3, .... );
I also tried to find a way to quickly convert from TBytes ( System.TArray<System.Byte>) and array [0..24] Byte, for example:
bytes2 := byte;
Unfortunately, the closest I can get is brute force code:
SetLength(bytes2,Length(bytes)); for n := 0 to Length(bytes) do begin bytes2[n] := bytes[n]; end;
It seems to me that the two types are so closely related to each other that the compiler can improve the work a bit, allowing me to force or copy, from one type to another. Does anyone else think of the different types of "Array X" like that? Know any steep paths around him? If the compiler did some magic, it could make the Move (...) function work in this case, but Move actually gives you access violation and cannot be used with dynamic arrays or generic collections.