1. Computing & Technology

Discuss in my forum

Copy RTF Text/Formatting From one TRichEdit to Another

By , About.com Guide

RichEdit Copy RTF

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; 

Delphi tips navigator:
» Is there an Image in the TImage Delphi Control?
« Programmatically Get and Set the MediaPlayer Sound Volume

©2012 About.com. All rights reserved.

A part of The New York Times Company.