Saving images to stream and inserting

General TRichView support forum. Please post your questions here
Post Reply
michal_t
Posts: 2
Joined: Tue Nov 23, 2010 9:15 am

Saving images to stream and inserting

Post by michal_t »

Hello,
In RichViewEdit I have a text with an image loaded from HTML (through RvHtmlImporter). I want to mark a part of the text with this image and load it to another RichViewEdit object.
I am doing it like this:

Code: Select all

TMemoryStream*  Stream = new TMemoryStream();
RichViewEdit1->SaveRVFToStream(Stream, true);
Stream->Position = 0;
RichViewEdit2->AppendRVFFromStream(Stream, -1);
In the second RichViewEdit object only the text appears, a space instead of image. Using InsertRVFFromStream gives the same result. Could you help me in finding a solution?[/code]
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Probably it happens because a graphic class used for this image is not registered.
For example, if you use C++Builder 2009 or newer, you can write:

Code: Select all

RegisterClass(__classid(TGIFImage));
RegisterClass(__classid(TPngImage));
Call this code one time, before the first RVF loading.
michal_t
Posts: 2
Joined: Tue Nov 23, 2010 9:15 am

Post by michal_t »

Thank you very much,
Actually the problem was much more simply and stupid. The option rvfoSavePictureBody was not enabled - my fault.

I hava another problem. I have 2 RichViewEdit objects and want to copy a part of the text, with images, from RVE1 to RVE2. The text which I am copying from RVE1 is written in green font but after inserting to RVE2 it changes to black. I worked it around by selecting what was inserted and use the function ApplyTextStyle, but probably there is a better solution. Is it possible to keep the style of inserted text. I am using the following code:

Code: Select all

//TransStream is defined as TMemoryStream*
RichViewEdit1->SaveRVFToStream(TransStream, false);
//The text in RichViewEdit1 is green
TransStream->Position = 0;
RichViewEdit2->InsertRVFFromStreamEd(Form2->TransStream);
//The text inserted is black (default style)
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Right click RichViewEdit1 in IDE. Choose "Settings" in the context menu. Select "Allow adding styles dynamically".
The same for RichViewEdit2.
(actually, these options must be set by default for RichViewEdits placed on a form at design time; if you create them in code, you need to set properties manually).

Also, make sure that the both editors are linked to their own RVStyle components.
Post Reply