trichview.com

trichview.support




Re: Unicode and SaveRVFToStream.


Return to index


Author

Message

Sergey Tkachenko

Posted: 05/16/2004 13:43:39


> Hi

>

> I want to support Unicode in my application.

>

> I would like to know how to save the content to a Stream then covert

> that to string variable.

>

> All text styles' Unicode properties are set to true.


Do not foget also to set RichView.RTFReadProperties.UnicodeMode =

rveuOnlyUnicode, otherwise non-Unicode characters may appear when

loading/inserting/pasting RTF.


>

> Below is my code. I get scrambled characters with that.

>

> Please help me out.



> TMemoryStream *l_Stream = new TMemoryStream();

> RichViewEdit1->SaveRVFToStream(l_Stream, false);

>

> WideString l_Buffer;

> l_Buffer.SetLength(l_Stream->Size);

> l_Stream->Position = 0;

> l_Stream->Read(l_Buffer.c_bstr(), l_Buffer.Length()*sizeof(wchar_t));

> delete l_Stream;

>

> ShowMessage(l_Buffer);


SaveRVFToStream saves document in internal format (RVF). It's not Unicode,

not non-Unicode, it's a binary format.

(by the way, you must not multiply by sizeof(wchar_t), l_Buffer contains

exactly l_Buffer.Length() bytes)


Use RichViewEdit1->SaveTextToStreamW() instead of

RichViewEdit1->SaveRVFToStream()


TMemoryStream *l_Stream = new TMemoryStream();

RichViewEdit1->SaveTextToStreamW('', l_Stream, 80, false, false);


WideString l_Buffer;

l_Buffer.SetLength(l_Stream->Size/2);

l_Stream->Position = 0;

l_Stream->Read(l_Buffer.c_bstr(), l_Buffer.Length());

delete l_Stream;


ShowMessage(l_Buffer);


Note1: in l_Buffer.SetLength(), l_Stream->Size is divided by 2 (size of wide

char). This is because SetLength() parameter is a number of characters, not

bytes.

Note2: in l_Stream->Read(), l_Stream->Size is used. This is because this

parameter is a number of bytes, not characters.





Powered by ABC Amber Outlook Express Converter