How can I switch to Rich Edit 4.1 (or higher) in Delphi 11.1.5

332 Views Asked by At

I have character encoding problems with the base TRichEdit component in Delphi 11.1.5. It does not handle in its output RTF the situation if I switch the keyboard language and type hun/en special characters (ő/ű/²). It just stores one codepage at the \ansicpgN and does not store it in the font table item \fN\cpgN, and it uses \'NN codes instead of \uNNNN. Bing said if I switch to RichEdit 4.1, it will solve my problem. But how can I switch? Could somebody help me?

Bing said I should call this in the OnCreate event of the form containing the TRichEdit control:

SetWindowLong( RichEdit1.Handle, GWL_WNDPROC, HashCode( 'RICHEDIT41' ) );

But it could not define the proper hash function to provide a working hash code.

Here it is a very simple, but problematic RTF doc:

{\rtf1\ansi\ansicpg1250\deff0\nouicompat\deflang1038{\fonttbl{\f0\fnil\fcharset238 Arial;}{\f1\fnil\fcharset0 Arial;}{\f2\fnil\fcharset238 Times New Roman;}}
{\colortbl ;\red255\green0\blue0;}
{\*\generator Riched20 10.0.19041}\viewkind4\uc1 
\pard\f0\fs24\'f5\f1\lang1033\'b2\cf1\f2\lang1038\'fb\f0\par
}

In this example, I should convert the ANSI \'F5 and \'fb characters with codepage 1250, but the ANSI \'b2 character with codepage 1252 to get the right UTF-16 string : 'ő²ű'.

The \fN selects the font, but these store the \fcharsetN and not the required \cpgX values.

But with RichEdit 4.1 the \cpgN I won't miss at all, because it stores the special character codes encoded in UTF-16 format : \uNNNN in the contents section.

1

There are 1 best solutions below

2
Remy Lebeau On

TRichEdit already uses RichEdit 4.1, and has since the initial release of Delphi 11:

TRichEdit Component updated to RichEdit 4.1 (MSFTEDIT.dll)

In any case, TRichEdit itself does not (and never has) format the actual RTF itself, that is all Microsoft's doing. So whatever problems you are having with the RTF should be taken up with Microsoft, not Embarcadero. TRichEdit simply sends the underlying RichEdit an EM_STREAMOUT message and Microsoft does all the work to create the RTF, TRichEdit just writes the output to the caller's provided TStream object.

Also, you can't pass in a hash code to SetWindowLong(GWL_WNDPROC), as it wants an actual function pointer instead. Bing is giving you bad/incomplete information.