Q:

Is there a clean way to declare a TBytes-compatible value at compile time?

If I wanted to declare a static compile-time array of Byte, I could do it like this:
var
  bytes :array[0..24] of Byte = (1, 2, 3, .... );

However, the type of that is array[0..24] of byte, not System.TArray<System.Byte>, which is more commonly known as TBytes.
What I need is something that can be of type TBytes but I don't want to have 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 some way to do this instead:
var
    bytes2:TBytes = (1,2,3, .... );

I tried also to find a way to convert quickly from  TBytes (System.TArray<System.Byte>) and array[0..24] of Byte, like this:
 bytes2 := byte;

Unfortunately, the closest I can get is this brute-force code:
  SetLength(bytes2,Length(bytes));
  for n := 0 to Length(bytes) do begin
     bytes2[n] := bytes[n];
  end;

It seems to me for two types so closely related, that the compiler could do a little better job of allowing me to coerce or copy, from the one type to the other.  Anybody else feel that way about various types of "Array of X"?  Know any cool ways  around it? If the compiler did some magic, it might make the Move(...) function work for this case, but Move actually gives you an access violation, and can't be used with dynamic arrays or generic collections.

A:

How about:
var
  bytes: TBytes;
begin
  bytes := TBytes.Create(1,2,3, .... );
end;

That said I always find it limiting that this syntax does not accept open arrays. So I have a bunch of functions that look like this:
function Bytes(const A: array of Byte): TBytes;
var
  i: Integer;    
begin
  SetLength(Result, Length(A));
  for i := low(Result) to high(Result) do
    Result[i] := A[i];
end;
...
var
  b1, b2: TBytes;
  b3: array of Byte;
  b4: array [0..42] of Byte;
...
  b1 := Bytes(b2);
  b1 := Bytes(b3);
  b1 := Bytes(b4);
  b1 := Bytes([1,2,3,4]);

I believe that the various generics enhancements in XE mean that this could be done with generics and without duplicating routines like Bytes for each different scalar.

