Since TBytes, TByteDynArray, and array of Bytes are all dynamic arrays of bytes, can typed variables be safely typecasted to each other? (If I have a variable of TBytes can I simply typecast to TByteDynArray when using a method that defines parameters as TByteDynArray and vice-versa?)
Since TBytes , TByteDynArray , and array of Bytes are all dynamic arrays of
Share
Such typecasts are perfectly safe in all the Delphi implementations that I have ever encountered.
However, reinterpretation typecasts like this remove type checking, there is always a risk that future changes to the source code can result in hard to trace errors. I would always try to avoid casting if possible. For example, the very simplest thing you can do is to avoid using
array of Byteas a type in your code and switch toTBytes.If you must cast then wrap it up in a function to mitigate the risks I describe above.