Delphi XE4 Indy compatibility issue between TBytes and TidBytes

delphi, indy

Solution

The reason `TIdBytes` was a simple alias for `TBytes` in earlier Indy 10 releases was primarily for compatibility with `SysUtils.TEncoding`, which uses `TBytes`. Indy's `TIdTextEncoding` type used to be a simple alias for `SysUtils.TEncoding` in D2009+, so `TIdBytes` needed to be a simple alias for `TBytes` to match.

However, `TBytes` caused quite a bit of trouble for Indy in XE3, mainly because of RTTI problems with Generics (`TBytes` is a simple alias for `TArray<Byte>` in recent Delphi releases). So, Indy 10.6 re-designed `TIdTextEncoding` to no longer rely on `SysUtils.TEncoding` at all (there were other reasons as well for doing so), which then allowed `TIdBytes` to change into its own array type in order to avoid the XE3 issues moving forward.

On the other hand, you were passing a `TBytes` where a `TIdBytes` was expected, so that is bad programming on your part for not following Indy's defined interface in the first place. All of Indy 10's byte-based operations, including `ReadBytes()`, have always operated on `TIdBytes` only. The fact that `TIdBytes` silently mapped to `TBytes` was an implementation detail that you should not have relied on in your code. Indy 10 expects `TIdBytes`, so use `TIdBytes`, then you would not have compiler errors about incompatible types.

Problem

Today I try to compile my XE3 project in XE4. First problem that I face is with Indy's FTCPClient.Socket.ReadBytes() method. Before it was accepting TBytes type, now it insists on TidBytes. Definitions: TIdBytes = array of Byte; TBytes, Im not sure I guess it is generics something like TArray which is array of Byte. Question number 1: Why does compiler complain by saying that'[dcc32 Error] HistoricalStockData.pas(298): E2033 Types of actual and formal var parameters must be identical'. As I see they are already identical. Question number 2: Should I modify my source code with the each new delphi version? Thanks.

Original source