Page 1 of 1

Saving images to stream and inserting

Posted: Tue Nov 23, 2010 9:24 am
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]

Posted: Tue Nov 23, 2010 5:16 pm
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.

Posted: Wed Nov 24, 2010 7:47 am
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)

Posted: Wed Nov 24, 2010 4:18 pm
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.