When porting some communications code that used records as properties from Delphi 2006 to Delphi XE2, I came across a tightened compiler error “E2197 Constant object cannot be passed as var parameter“.
Let me first explain the good old occurrence of E2197 with some code that uses my last Variant Records example:
Just look at TPacket.InitializePacket
and TPacketBase.InitializeFPacket
: Basically even though the Packet
property has storage specifiers indicating it directly reads from a field and directly writes to a field, you cannot pass it as a var parameter in the FillChar method.
Of course you can with a field, you can pass it to FillChar without trouble as TPacketBase.InitializeFPacket
shows. Read the rest of this entry »