jpfollenius
jpfollenius

Reputation: 16612

Converting Unicode Stream to String List in D2007

In a D2010 application I do

StringList.SaveToStream (MemStream, TEncoding.Unicode);

I then send this stream over the network to some 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.

Upvotes: 2

Views: 3116

Answers (2)

Jeroen Wiert Pluimers
Jeroen Wiert Pluimers

Reputation: 24483

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

Upvotes: 2

da-soft
da-soft

Reputation: 7750

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.

Upvotes: 4

Related Questions