简体   繁体   English

在 Delphi XE 中读取 TStream 时出现问题

[英]Problem reading a TStream in Delphi XE

In the previous versions of Delphi, the following code:在之前版本的Delphi中,代码如下:

   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 ).用正确的值填充变量 InBuf (每个字节都有一个值)。 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.现在在 Delphi XE 中,数组的第二个字节为 0,我想是因为 Byte 数据类型是两倍大,因为它在 Delphi 中的 Unicode 性质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.这里发生的情况,有 >99% 的可能性是您从字符串变量中编写了 stream。 Unicode strings with UTF-16 encoding have two bytes per character whereas older versions of Delphi using ANSI encodings with one byte per character.使用 UTF-16 编码的 Unicode 字符串每个字符有两个字节,而旧版本的 Delphi 使用 ANSI 编码,每个字符一个字节。

English text, when encoded with UTF-16 have the pattern you observe of every second byte being zero.使用 UTF-16 编码的英文文本具有您观察到的每隔一个字节为零的模式。

In order to solve this you will need to investigate the section of code that writes to the stream.为了解决这个问题,您需要研究写入 stream 的代码部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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