开发者

What could cause a "richedit line insertion error" in C++Builder when inserting text in a different language?

I have a C++Builder application using a TRichText control that has to display a report, running under Windows XP. The application was written in English but has been adapted to use other languages. Creating text on the TRichEdit (using the RichEdit->Lines->Add() function) is no problem as long as I am using 开发者_开发技巧Western languages. When I'm trying to add Russian (Cyrillic) text however the application throws an EOutOfResources exception with the "RichEdit line insertion error". Now this exception is usually thrown when the amount of text exceeds the RichEdit internal buffer (64KB) but that is certainly not the case and even adding one character fails.

It is not a unicode application so I have to switch codepages to see the application in Cyrillic.And then I can see all other texts (like menus and labels) are displayed correct.

So what else could cause this error ?


RTF expects anything outside of 7-bit ASCII to be escape sequences. See this page for more details on the escape sequences. I think the section that details control page encoding would be most useful for you.


Research shows it's a problem that only occurs on Windows XP. Also the error does not occur when the Windows XP has the locale settings for the specific language. The problem seems to be in the RichEd32.dll that is supplied with this version of Windows. The VCL (Visual Component Library as used by C++Builder and Delphi) fails when the first character of a line of text that is added to the TRichText control is an escaped character. The solution is to use the following code to add a line:

AnsiString TextToAdd;
TextToAdd = "пример"; // Russian text 'example'

RichEdit1->SelStart = RichEdit1->Text.Length();
RichEdit1->SelText = TextToAdd + "\r\n";

Instead of:

RichEdit1->Lines->Add( TextToAdd );

This actually has to be done only once. After text was added to any RichEdit control in the application, all subsequent calls to 'Lines->Add()' will work without throwing the exception.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜