1. Home
  2. Computing & Technology
  3. Delphi Programming

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

More Delphi Programming Quick Tips
Explore Delphi Programming
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Using VCL Components
  5. TMemo, TRichEdit
  6. Copy RTF Text with Formatting from one TRichEdit to Another in Delphi applications

©2009 About.com, a part of The New York Times Company.

All rights reserved.