开发者

Converting Unicode Stream to String List in D2007

开发者 https://www.devze.com 2023-01-31 08:56 出处:网络
In a D2010 application I do StringList.SaveToStream (MemStream, TEncoding.Unicode); I then send this stream over the network to som开发者_运维技巧e client applications. This part of the code is fix

In a D2010 application I do

StringList.SaveToStream (MemStream, TEncoding.Unicode);

I then send this stream over the network to som开发者_运维技巧e client applications. This part of the code is fixed (I cannot change it):

Now I have a D2007 application that needs to receive this stream and convert it back to a string list. D2007 does not include Unicode support and the TEncoding class. How can I convert the stream into a string list? Something similar to

StringList.LoadFromStream (MemStream, TEncoding.Unicode)

in D2010...

Thanks for any help.


In Delphi 2007 you have few options:

  1. Use TWideStrings.
  2. Read the stream content into WideString variable and assign it value to the TStrings.Text property.


Edit: since you cannot change your Delphi 2010 code, I'd use the TWideStrings class from the WideStrings unit in Delphi 2007: that class supports unicode strings.

Note that when encoding in Delphi 2010, you will find a BOM (byte order mark) at the start of the stream.

I would save the stream in Delphi 2010 as UTF8 (TEncoding.UTF8), then in Delphi 2007 use the function UTF8Decode(const S: UTF8String): WideString; (docs) from the System unit.

--jeroen

0

精彩评论

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