Title: Copy RTF Text with Formatting from one TRichEdit to Another in Delphi applications
Delphi's TRichEdit control is a text edit control that allows the user to enter text that includes variation in font attributes and paragraph formatting information.
The TRichEdit can display RTF (rich text format) documents. RTF files are actually ASCII files with special commands to indicate formatting information, such as fonts and margins.
Here's how to copy the text from one RichEdit to another, without loosing the RTF formatting!
Note: Drop 2 TRichEdit controls on a Delphi form. Name them RichEdit1 and RichEdit2. Add some RTF text to RichEdit1 and execute the next code to copy the text to the second rich edit without loosing the RTF formatting.
var
ms: TMemoryStream;
begin
ms := TMemoryStream.Create;
try
RichEdit1.Lines.SaveToStream(ms) ;
ms.Seek(0, soFromBeginning) ;
RichEdit2.Lines.LoadFromStream(ms) ;
finally
ms.Free;
end;
end;