什么可能导致“richedit 行插入错误”?在 C++Builder 中插入不同语言的文本时?
我有一个使用 TRichText 控件的 C++Builder 应用程序,该应用程序必须显示报告,在 Windows XP 下运行。该应用程序是用英语编写的,但已改编为使用其他语言。只要我使用西方语言,在 TRichEdit 上创建文本(使用 RichEdit->Lines->Add() 函数)就没有问题。然而,当我尝试添加俄语(西里尔文)文本时,应用程序会抛出 EOutOfResources 异常,并显示“RichEdit 行插入错误”。现在,当文本量超过 RichEdit 内部缓冲区 (64KB) 时,通常会引发此异常,但事实并非如此,甚至添加一个字符也会失败。
它不是 unicode 应用程序,因此我必须切换代码页才能以西里尔字母查看该应用程序。然后我可以看到所有其他文本(如菜单和标签)都正确显示。
那么还有什么可能导致这个错误呢?
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 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
RTF 期望 7 位 ASCII 之外的任何内容都是转义序列。有关转义序列的更多详细信息,请参阅此页面。我认为详细控制页面编码的部分对您最有用。
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.
研究表明该问题仅出现在 Windows XP 上。当 Windows XP 具有特定语言的区域设置时,也不会发生该错误。问题似乎出在随该版本的 Windows 提供的 RichEd32.dll 中。当添加到 TRichText 控件的文本行的第一个字符是转义字符时,VCL(C++Builder 和 Delphi 使用的可视化组件库)将失败。解决方案是使用以下代码添加一行:
而不是:
这实际上只需要做一次。将文本添加到应用程序中的任何 RichEdit 控件后,对“Lines->Add()”的所有后续调用都将正常工作,而不会引发异常。
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:
Instead of:
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.