Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

RichEdit and WideString containing Unicode results in '?'

13 views
Skip to first unread message

Gerhard Zampich

unread,
Dec 10, 2003, 11:49:30 AM12/10/03
to
Hallo,

I have a RichEdit on my form and a WideString containing Unicode
characters in Chinese and/or Cyrillic.
I am able to directly type the Chinese or Cyrillyc characters into the
RichEdit with the keybord.
But i am unable to fill the RichEdit from my WideString.

RichEdit1.SelText := aWideString;

results in '?' for any Unicode character.

Is there any Windows API that allows me to set text in a RichEdit from a
WideString containing Unicode?

Thanks in advance
Gerhard


Peter Below (TeamB)

unread,
Dec 11, 2003, 2:44:35 PM12/11/03
to

You can try

SendMessageW( richedit1.handle, EM_REPLACESEL, 0,
lparam( Pointer(aWideString )));

but i doubt that it will work. The VCL creates the richedit control using
CreateWindowA, which tells Windows that your program is not UNICODE-aware
and that all messages passing character data to the control will contain
ANSI/MBCS encoded characters. Windows then takes it upon itself to
translate any such messages send via SendMessageW to to ANSI/MBCS.

Your best bet may be to trawl the net for an UNICODE version of TRichedit.
Two URLs of interest:
http://www.delphi-unicode.net/
http://home.ccci.org/wolbrink/tntmpd/delphi_unicode_controls_project.htm

The next best bet is to investigate use of the TOM (Text Object Model)
interfaces. From the docs this would look somewhat like this:

uses Richedit;

var
Intf: IRicheditOle;
TOMDocument: ITextDocument;
Selection: ITextSelection;
begin
if 0 <> richedit1.perform( EM_GETOLEINTERFACE, 0, lparam(@Intf))
then begin
if Supports( Intf, ITextDocument, TOMDocument ) then begin
TOMDocument.GetSelection( Selection );
if Assigned( Selection ) then
Selection.SetText( aWideString );
end;
end;
end;

Untested, no warranties! The TOM interfaces seem to be absent from the API
translation as supplied with Delphi, you may have to get a more complete
translation (especially of tom.h)from one of these sites:

http://delphi-jedi.org/APILIBRARY
http://members.chello.nl/m.vanbrakel2


--
Peter Below (TeamB)
Use the newsgroup archives :
http://www.mers.com/searchsite.html
http://www.tamaracka.com/search.htm
http://groups.google.com
http://www.prolix.be


Colin Wilson

unread,
Dec 17, 2003, 9:59:35 AM12/17/03
to
Gerhard Zampich wrote:

> Is there any Windows API that allows me to set text in a RichEdit
> from a WideString containing Unicode?

You can send the control an EM_EMSTREAMIN message, with the SF_TEXT and
SF_UNICODE flags set.

There's a free Unicode rich edit control available on my website. It
comes with source so you can see what needs to be done. Go for the
'Miscellaneous Components' package. It's called TExRichEdit

--
Colin - using XanaNews HTTP Transport
e-mail :co...@wilsonc.demon.co.uk
web: http://www.wilsonc.demon.co.uk/delphi.htm

Posted with XanaNews 1.15.8.4

0 new messages