Delphi复制备忘录到Richedit问题

发布于 2024-10-04 11:12:57 字数 294 浏览 12 评论 0原文

我在将备忘录的内容复制到 richedit 组件时遇到问题。

我以为会是

Richedit.text := memo.text;

但是如果我使用它,当备忘录文本换行到新的新行(不是 CR/LF)但只是换行时,Richedit 会开始一个新行。当备忘录开始新行时,richedit 也会开始新行,这很好。

任何人都知道如何将备忘录中的文本复制到 Richeditbox 中,当备忘录文本换行时,Richedit 中不会出现断行

谢谢

Colin

I am having a problem copying the contents of a memo to a richedit component.

I thought it would be

Richedit.text := memo.text;

However if I use this the Richedit starts a new line when the memo text wraps to a new a new line (not CR/LF) but just wrapping. The richedit also starts a new line when the memo starts a new line which is fine.

Anyone got any idea's how to copy the text from a memo into the richeditbox without the lines breaking in the Richedit when the memo text wraps

Thanks

Colin

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

携余温的黄昏 2024-10-11 11:12:57

当我这样做时,

RichEdit1.Text := Memo1.Text

Memo1 的虚拟“换行符”不会神奇地转换为 RichEdit 中的换行符 (CRLF),而且也不应该如此。这些“换行符”不存储在备忘录文本缓冲区中。事实上,Embarcadero 官方文档指出

将 WordWrap 设置为 true 以使编辑控件在右边距处换行文本,使其适合客户区。包装只是装饰性的。文本不包含任何未明确输入的返回字符。

无论如何,另一种方法是这样做,

RichEdit1.Lines.Assign(Memo1.Lines);

尽管这将保留虚拟换行符,如下所述。

更新

很可能您的代码中有一些其他奇怪的地方(错误),或者您以过于模糊的方式表达了您的问题。但是,要消除 VCL 包装器出现任何问题的风险,请尝试以下操作:

procedure TForm4.FormClick(Sender: TObject);
var
  buf: PChar;
const
  MAX_BUF_SIZE = 65536;
begin
  GetMem(buf, MAX_BUF_SIZE * sizeof(char));
  Memo1.Perform(WM_GETTEXT, MAX_BUF_SIZE, buf);
  RichEdit1.Perform(WM_SETTEXT, 0, buf);
  FreeMem(buf);
end;

When I do

RichEdit1.Text := Memo1.Text

the virtual "line-breaks" of the Memo1 are not magically converted to line-breaks (CRLF) in the RichEdit, and they shouldn't be. These "line-breaks" are not stored in the memo text buffer. Indeed, the official Embarcadero documentation states

Set WordWrap to true to make the edit control wrap text at the right margin so it fits in the client area. The wrapping is cosmetic only. The text does not include any return characters that were not explicitly entered.

Anyhow, an alternative way is to do

RichEdit1.Lines.Assign(Memo1.Lines);

although this will preserve the virtual line-breaks, as commented below.

Update

Most likely you have some other strangeness (bug) in your code, or you have phrased your question in a too vague manner. However, to eliminate the risk of any problem with the VCL wrappers, try this:

procedure TForm4.FormClick(Sender: TObject);
var
  buf: PChar;
const
  MAX_BUF_SIZE = 65536;
begin
  GetMem(buf, MAX_BUF_SIZE * sizeof(char));
  Memo1.Perform(WM_GETTEXT, MAX_BUF_SIZE, buf);
  RichEdit1.Perform(WM_SETTEXT, 0, buf);
  FreeMem(buf);
end;
桃扇骨 2024-10-11 11:12:57

作为一个肮脏的黑客,你可以关闭备忘录上的自动换行,然后做作业,然后重新打开自动换行吗?这是一个令人讨厌的黑客行为,但如果有一些奇怪的行为,它可能会为你带来好处。

As a dirty hack, could you switch off word wrap on your memo then do the assignment and then switch word wrap back on? It's a nasty hack but it might do the trick for you if there is some odd behaviour.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文