If I try
RichEdit2.text:=RichEdit1.text;
it copies the text without the formatting, and so does
RichEdit2.lines:=RichEdit1.lines;
Thanks for any insight on this.
> How can I copy the formatted contents of one
> TRichEdit control to another?
Use the SaveToStream() and LoadFromStream() methods, setting the PlainText
property to False on both TRichEdit instances beforehand.
var
Stream: TStream;
Old: Boolean;
begin
Stream := TMemoryStream.Create;
try
Old := RichEdit1.PlainText;
RichEdit1.PlainText := False;
try
RichEdit1.Lines.SaveToStream(Stream);
finally
RichEdit1.PlainText := Old;
end;
Old := RichEdit2.PlainText;
RichEdit2.PlainText := False;
try
Stream.Position := 0;
RichEdit2.Lines.LoadFromStream(Stream);
finally
RichEdit2.PlainText := Old;
end;
finally
Stream.Free;
end;
end;
Gambit
Try:
wealthyedit.lines.assign(richedit.lines);
--
Blackbird Crow Raven, NSGW
> wealthyedit.lines.assign(richedit.lines);
That will not work. It also strips off the formatting. The
SaveTo/LoadFromStream() methods are the only way to preserve formatting
(well, that and alternatively copying the formatted RTF to the clipboard and
then pasting it, but using a stream is better).
Gambit