TBytes
and TIdBytes
are both implemented as dynamic arrays, they are simply declared differently. The "politically correct" solution is to make a copy of the bytes. But that can waste memory for large arrays. A simpler solution is to use a typecast so you can utilize the array's internal reference count, eg:
type
PIdBytes = ^TIdBytes;
var
B1: TBytes;
B2: TIdBytes;
begin
B1 := ...;
B2 := PIdBytes(@B1)^;
end;
Or simply:
var
B1: TBytes;
B2: TIdBytes;
begin
B1 := ...;
B2 := TIdBytes(B1);
end;