开发者

Problem reading a TStream in Delphi XE

开发者 https://www.devze.com 2023-03-22 02:15 出处:网络
In the previous versions of Delphi, the following code: var InBuf: array[1..45] of Byte; Count := InStream.Read(InBuf, SizeOf(InBuf));

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消