组合多个TBytes阵列的最佳方法

Vin*_*gar 5 delphi bytearray delphi-xe2

组合TBytes数组的最佳方法是什么?

所有阵列都具有相同的大小.我希望将内容Array2添加到结尾Array1,Array3结束Array2等等.

Rem*_*eau 9

要将两个合并TBytes在一起,您必须分配第三个TBytes,即两个人的总长度TBytes,然后将两者中的字节复制到其中.例如:

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;
Run Code Online (Sandbox Code Playgroud)