2

我在使用 TRichEdit 时遇到了一些问题。

第一个问题是如果我尝试将剪贴板中的大量文本粘贴到一个空的 TRichEdit 中,它会截断文本的底部。

第二个问题,我猜想与第一个问题有关,我似乎受限于 TRichEdit 可以显示的字符数,因此从剪贴板粘贴会丢失一些数据。

如果我粘贴到 TJvRichEdit (Jedi) 中,效果很好,显然因为这是一个完全不同的组件。

此时此刻,我想要一个 TRichEdit 的解决方案,因为我正在使用很多程序/函数等,如果我更改为不同的 Rich Edit 类,那么我将不得不编辑很多代码才能工作。

所以基本上我要问的是:

  • TRichEdit 有限制吗?我确信有。
  • 如何增加 TRichEdit 的限制以接受更多字符和行等。

请仅为 TRichEdit 提供建议/解决方案。

编辑

没关系使用以下方法找到答案:

RichEdit11.MaxLength := $7FFFFFF0;
4

1 回答 1

3

引用新闻组中 David Pate 的回答:

以下备注适用于使用 Windows Richedit 版本 1 控件的 Delphi 版本。我知道这包括版本 7 之前的所有 Delphi 版本。(我不知道当您在各种 NT/2000 版本的 Windows 上运行以这些版本编译的程序时会发生什么情况,尽管 Windows XP 的行为与描述的一样。)

问:Richedit 可以容纳的文本数量有什么限制?A. 帮助文件(Delphi 帮助和 Win32 SDK)在这一点上是混乱的、矛盾的和不正确的。有5个限制需要考虑

  1. The Maximum Capacity: the "hard-wired" limit, i.e the maximum size of the RichEdit's text buffer. It is 2 bytes less than 2 Gb. Note that this is the theoretical limit; in practice the limit will be determined by your computer's memory.

  2. The Capacity: the actual size of the current buffer. By default, it is 64Kb but can be resized by several means.

  3. The "Keyboard limit": the limit beyond which characters cannot be added by typing from the keyboard. It is often different from the Capacity but, like the Capacity, it is by default, 64Kb and can be resized by several means.

  4. The MaxLength property of the tRichEdit object. The default of 0 sets both the Capacity and "Keyboard limit" to 64Kb.

  5. The line-number limit: theoretically this is around 134 million, but in practice, you can expect to get much less than this. The maximum number of lines seems to depend on several factors including the amount of memory available and the average length of the lines. I find that I can get around 150 thousand to 200 thousand lines. Note also that it has been reported that some releases of the Windows 95 Richedit control sometimes throw an exception when more than a few hundred lines are added. This appears to be due to a bug in the control and to have been corrected in later releases..

Q. How can I increase the amount of text that a tRichEdit can hold?

A. When you add text programmatically, both the Capacity and the "Keyboard limit" are resized to accommodate the text being added. By adding text programmatically, I mean using any of the Add, Append, AddStrings or Assign methods of the tRichEdit.Lines property or the LoadFromFile, LoadFromStream or SetTextBuf methods of tRichEdit. Note that adding text in this way does not update the MaxLength property.

B. By using the MaxLength property. This sets the "Keyboard limit" to the value passed to MaxLength. It also increases the Capacity to match the "Keyboard limit" if the existing Capacity is less than MaxLength. Note that you cannot use MaxLength to reduce the Capacity and that changing MaxLength has no effect if the value passed is less than the length of the text currently in the control. To increase the Capacity and the "Keyboard limit" to the same value, set the tRichEdit.MaxLength to the desired value. To set the maximum size in the Object Inspector, use the value 2147483645 ($7FFFFFFD). To set it programmatically it is simpler to use .MaxLength := System.MaxInt-2;. The EM_LIMITTEXT and EM_EXLIMITTEXT messages may also be used to change the "Keyboard limit" and Capacity but I'd not normally recommend using them since, if you do, you will not be updating the MaxLength property.

于 2011-05-18T20:34:41.800 回答