What is the best way to combine TBytes arrays?
All arrays are of the same size. I want the content of Array2 to be added to the end of Array1, Array3 to the end of Array2, and so forth.
To merge two TBytes together, you have to allocate a third TBytes that is the total length of the two individual TBytes, then copy the bytes from both into it.  For example:
var
  arr1, arr2, merged: TBytes;
begin
  ...
  SetLength(merged, Length(arr1) + Length(arr2));
  if arr1 <> nil then Move(arr1[0], merged[0], Length(arr1));
  if arr2 <> nil then Move(arr2[0], merged[Length(arr1)], Length(arr2));
end;
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With