Board index » cppbuilder » Saving the rich text contents of a TRichEdit into a temporary buffer

Saving the rich text contents of a TRichEdit into a temporary buffer

I have a MDI form with 4 MDIChildren (imagine 4 different images on each
one). There is another form (kind of wordpad with a TRichEdit).
On that RichEdit I may have the coments about any of the images (the active
one each time). So when the ActiveMDIChild changes the text should change
too.
I want 4 temporary buffers to keep the contents of the non active forms.
I've tried with 4 TMemoryStreams, but I'm afraid I'm not using the
Lines->LoadFromStream ,SaveToStream because the program crashes when I try
to do it, or it shows no text.
Which is the best way to store the rich text (not in a File please)?
 

Re:Saving the rich text contents of a TRichEdit into a temporary buffer


Hi Manuel,

Quote
> I want 4 temporary buffers to keep the contents of the non active forms.
> I've tried with 4 TMemoryStreams, but I'm afraid I'm not using the
> Lines->LoadFromStream ,SaveToStream because the program crashes when I try
> to do it, or it shows no text.

The TMemoryStream class should serve you well, along with preserving the
RichText formatting.  Perhaps you can post a few lines of your code that
demonstrates the "crash".

Good luck!

--
Damon Chandler
http://bcbcaq.freeservers.com

Re:Saving the rich text contents of a TRichEdit into a temporary buffer


void __fastcall TEditor::RichEdit1Exit(TObject *Sender)
{
TMemoryStream *Buffer;
Buffer=new TMemoryStream();
RichEdit1->Lines->SaveToStream(Buffer);
RichEdit1->Lines->Clear();
RichEdit2->Lines->LoadFromStream(Buffer);
Quote
}

With this I try to send all the text in RichEdit1 to RichEdit2.
Nevertheless, the result is that both RichEdit control contents are cleared.
The text is lost.
What's wrong with it?
Damon Chandler escribi en mensaje <38B22428.6DBA4...@cornell.edu>...

Re:Saving the rich text contents of a TRichEdit into a temporary buffer


Hi Manuel,

You need to reset the current position of your memory stream...

Quote
> RichEdit1->Lines->SaveToStream(Buffer);
> RichEdit1->Lines->Clear();

  Buffer->Seek(0, soFromBeginning);

Quote
> RichEdit2->Lines->LoadFromStream(Buffer);

Good luck!

--
Damon Chandler
http://bcbcaq.freeservers.com

Re:Saving the rich text contents of a TRichEdit into a temporary buffer


Hello Manuel,

Manuel Blanco Medina <ma...@larural.es> schreef in berichtnieuws
88uh1m$5...@bornews.borland.com...

Quote
> void __fastcall TEditor::RichEdit1Exit(TObject *Sender)
> {
> TMemoryStream *Buffer;
> Buffer=new TMemoryStream();
> RichEdit1->Lines->SaveToStream(Buffer);
> RichEdit1->Lines->Clear();
> RichEdit2->Lines->LoadFromStream(Buffer);
> }

Hmm, you have to reset the TMemoryStream to its beginning.
Try Buffer->Position = 0; before streaming your text into RichEdit2...
And... do a delete Buffer; at the end of the Exit event...

Hope this helped...;-))

--
Greetings from sunny Amsterdam

                Jan

email: bijs...@worldonline.nl
http://home.worldonline.nl/~bijster

Re:Saving the rich text contents of a TRichEdit into a temporary buffer


It works
Thank you
Manuel Blanco

Damon Chandler escribi en mensaje <38B3F5AF.63220...@cornell.edu>...

Quote
>Hi Manuel,

>You need to reset the current position of your memory stream...

>> RichEdit1->Lines->SaveToStream(Buffer);
>> RichEdit1->Lines->Clear();

>  Buffer->Seek(0, soFromBeginning);

>> RichEdit2->Lines->LoadFromStream(Buffer);

>Good luck!

>--
>Damon Chandler
>http://bcbcaq.freeservers.com

Other Threads