Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Copying from one RichEdit to another

0 views
Skip to first unread message

Ken Pfeiffer

unread,
Mar 2, 2005, 1:24:55 PM3/2/05
to
How can I copy the formatted contents of one TRichEdit
control to another?

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.


Remy Lebeau (TeamB)

unread,
Mar 2, 2005, 3:13:30 PM3/2/05
to

"Ken Pfeiffer" <ke...@sonultra.com> wrote in message
news:422604f5$1...@newsgroups.borland.com...

> 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


Crazy Horse's crazier little brother

unread,
Mar 2, 2005, 3:13:46 PM3/2/05
to
"Ken Pfeiffer" <ke...@sonultra.com> wrote in message
news:422604f5$1...@newsgroups.borland.com...
> How can I copy the formatted contents of one TRichEdit
> control to another?
>
> If I try
>
> RichEdit2.text:=RichEdit1.text;
>
> it copies the text without the formatting, and so does
>
> RichEdit2.lines:=RichEdit1.lines;

Try:

wealthyedit.lines.assign(richedit.lines);

--
Blackbird Crow Raven, NSGW


Remy Lebeau (TeamB)

unread,
Mar 2, 2005, 3:58:23 PM3/2/05
to

"Crazy Horse's crazier little brother" <csha...@d4sw.com> wrote in message
news:4226...@newsgroups.borland.com...

> 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


0 new messages