ByteArray
is declared as a record
that internally holds an IBytes
interfaced object wrapping the byte data. TIdBytes
is declared as a simple dynamic array instead. As such, you can't directly typecast between them. You must copy the raw bytes back and forth.
You can do that manually, eg:
MyBytearray := ...;
MyTidBytes := RawToBytes(MyBytearray.Raw^, MyBytearray.Len);
// RawToBytes() is an Indy function in the IdGlobal unit...
...
MyTidBytes := ...;
MyBytearray := ByteArray.FromBytes(MyTidBytes);
// FromBytes() accepts any type of raw byte array as input, including dynamic arrays ...
Or, alternatively, ByteArray
has Implicit
conversion operators for TBytes
, and TIdBytes
is typecast-compatible with TBytes
as they are both dynamic arrays, eg:
MyBytearray := ...;
TBytes(MyTidBytes) := MyBytearray;
...
MyTidBytes := ...;
MyBytearray := TBytes(MyTidBytes);