简体   繁体   中英

Problem reading a TStream in Delphi XE

In the previous versions of Delphi, the following code:

   var InBuf: array[1..45] of Byte;

   Count := InStream.Read(InBuf, SizeOf(InBuf));

filled the variable InBuf with the correct values ( every byte had a value ). Now in Delphi XE, every second byte of the array is 0, I suppose because the Byte data type is twice as big, because of its Unicode nature in Delphi XE.But, my streams are already generated and need to pass through this procedure, so I need another type (maybe?) that is half size of Byte or another solution if someone faced this problem. Thanks

What has happened here, with >99% probability is that you have written the stream from a string variable. Unicode strings with UTF-16 encoding have two bytes per character whereas older versions of Delphi using ANSI encodings with one byte per character.

English text, when encoded with UTF-16 have the pattern you observe of every second byte being zero.

In order to solve this you will need to investigate the section of code that writes to the stream.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM