Delphi Copy Memo to Richedit problem
I am having a problem copying the contents of a memo to a richedit component.
I thought it would be
Richedit.text := memo.开发者_StackOverflow中文版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
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;
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.
精彩评论