Board index » delphi » How to copy TRichEdit contents to another TRichEdit?

How to copy TRichEdit contents to another TRichEdit?

What is the "proper" and "efficient" way to copy all of the text from one
TRichEdit to another without losing the formatting?

Craig Stephens

 

Re:How to copy TRichEdit contents to another TRichEdit?


Quote
Craig Stephens wrote:
> What is the "proper" and "efficient" way to copy all of the text from one
> TRichEdit to another without losing the formatting?

> Craig Stephens

Do this:

procedure TForm1.BitBtn1Click(Sender: TObject);
var
  TempStream : TMemoryStream;
begin
  TempStream := TMemoryStream.Create;

  RichEdit1.Lines.SaveToStream(TempStream);  // write list box contents to
the
                                            // stream
  TempStream.Position := 0;      // reset to the beginning of the stream
  RichEdit2.Lines.LoadFromStream( TempStream); // load stream contents into
rich
                                               // edit control

  TempStream.Free;
end;

Slightly modified code snippet from the online help -
SaveToStream, LoadFromStream example.

Happy streaming!

regards,

Lars-G?ran Andersson

Re:How to copy TRichEdit contents to another TRichEdit?


How about this one
        RichEdit1.SelectAll;
        RichEdit1.CopyTOClipBoard;
        RichEdit2.PasteFromClipBoard;

- Sunil Annam

Quote
Craig Stephens <stephen...@iname.com> wrote in message

news:7vc8c5$sn49@forums.borland.com...
Quote
> What is the "proper" and "efficient" way to copy all of the text from one
> TRichEdit to another without losing the formatting?

> Craig Stephens

Re:How to copy TRichEdit contents to another TRichEdit?


Quote
In article <7vc8c5$s...@forums.borland.com>, Craig Stephens wrote:
> What is the "proper" and "efficient" way to copy all of the text from one
> TRichEdit to another without losing the formatting?

You might like to download my CopyRTF unit
(http://www.3kcc.co.uk/copyrtf.zip).

The unit provides a simple method of copying RTF text between two RichEdit
controls. Data copied will be the source selected text or the whole
source if there is none selected. The copied data will replace the
destination selected text or be inserted at the current caret position.

Note: if running Delphi 5, you need to change the IFNDEF VER120 to VER130.

 Mike Orriss (TeamB)
 (Unless stated otherwise, my replies relate to Delphi 4.03/5.00)
 (Unsolicited e-mail replies will most likely be ignored)

Other Threads