Cell Streaming does not save Styles

General TRichView support forum. Please post your questions here
Post Reply
Michel
Posts: 92
Joined: Fri Oct 14, 2005 2:56 pm
Contact:

Cell Streaming does not save Styles

Post by Michel »

Hello,

I am trying to stream a cell's contents (with all styles) into a stream to later insert it into a different TDBRichViewEdit control with a different TRVStyle. No matter how I go about it, all I seem to be getting in the stream (I am saving it to a file to see what's there) is the text of the cell with Style indices, but not the Styles themselves. Since I'm using a different pair of RV/Style controls as targets where I end up inserting/appending/whatever the stream, the Style information gets lost.

The relevant portion of the code I am trying to use is:
TMemoryStream *MS = new TMemoryStream;
TRVTableCellData *Cell = Table->Cells[0][0];
Cell->SaveRVFToStream(MS, false, clNone, NULL, NULL);


Alternative (B) (to the last line above):
TCustomRVData *CRVD = Cell->GetRVData();
CRVD->SaveRVFToStream(...);


Or (C):
TRVTableInplaceRVData *CED = (TRVTableInplaceRVData *)Cell->Edit();
CED->SaveRVFToStream(...);


Or even (D):
TCustomRichViewEdit *CEDRV = (TCustomRichViewEdit *)CED->GetParentControl();
CEDRV->SaveRVFToStream(MS, false);


I have also tried SaveRVFToStreamEx(MS, rvfss_Full, clNone, NULL, NULL) for the first 3 (RVData) variants.
In all cases, I am getting the exact same output that looks like this:
-8 1 3
0 1 0 0 0 0
abc
22 1 -1 1 0 0
def
0 1 -1 1 0 0
ghi
23 1 -1 1 0 0
jkl

What I seem to be missing is the actual Styles #22 and #23 for "def" and "jkl".

The source TDBRichViewEdit is already in the "Allow adding styles dynamically" mode (which happens to be the default). The only non-default setting I can think of is: rvoTagsArePChars is true. I'm using version 1.9.
Is there something I'm doing wrong? Is there a (known) limitation related to Cell streaming? If so, is there a workaround?

Thank you in advance,

Michel
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Table cells really do not support saving and loading styles.
So the first code does not saved styles.

This code will work:

Code: Select all

Cell->Edit(); 
RichViewEdit1->TopLevelEditor->SaveRVFToStream(...); 
Michel
Posts: 92
Joined: Fri Oct 14, 2005 2:56 pm
Contact:

Post by Michel »

Hi Sergey,

Thank you for a very prompt response! However, it doesn't quite work.
Firstly, RichViewEdit->TopLevelEditor returns the exact same thing I was already getting in step (D) as CED->GetParentControl(), so I have essentially already tried what you suggested. I did of course try your alternative and it produced the exact same results.

While playing with this some more, I noticed the following peculiarity.

Code: Select all

TMemoryStream *MS = new TMemoryStream;
MS->Size = 100000;
<Any RVEdit or RVData>->SaveRVFToStream(MS, ...);
MS->SaveToFile("Check.bin");
The above produces a 100000-byte file regardless of the real size of what has been streamed (which is less). I doubt this problem is in any way related to my cell streaming troubles though. Just thought I'd mention it.

Is there anything else I can try with Cell+Style streaming?

Thank you,

Michel
Michel
Posts: 92
Joined: Fri Oct 14, 2005 2:56 pm
Contact:

Post by Michel »

Come to think of it, the "peculiarity" I spoke of is probably perfectly normal Stream behavior, so never mind that part.

The main Cell+Style streaming problem remains of course...

Thank you,

Michel
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Not tried, but I think you can reduce stream size by assigning Stream.Size := Stream.Position after saving.

As for the original problem, I'll verify it and answer tomorrow.
Michel
Posts: 92
Joined: Fri Oct 14, 2005 2:56 pm
Contact:

Post by Michel »

Hi Sergey,

Let me know as soon as you get a chance! Thanks again,

Michel
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

In the current TRichView version, there is no direct way to save cell in RVF with styles.
Workarounds:
- to select cell and save selection as RVF
or
- to save without styles, load in a hidden TRichView linked to the same RVStyle, then save this TRichView.
Michel
Posts: 92
Joined: Fri Oct 14, 2005 2:56 pm
Contact:

Workarounds Accepted!

Post by Michel »

Hi Sergey,

Thank you very much!
Workarounds:
- to select cell and save selection as RVF
Actually, this is what I have come up with on my side. I was simply hoping there was a better way.
- to save without styles, load in a hidden TRichView linked to the same RVStyle, then save this TRichView.
And this appears to be that better way I was looking for! In a little test project I did, it worked just fine. By this I mean that it saved cell text with styles, so I don't know why you wrote "to save without styles".

Thank you once again!

Michel
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

I meant

[Cell] --(RVF without styles)--> [Hidden RV] --(RVF with styles)-->
Post Reply