Merging data from one TRichViewEdit into another

General TRichView support forum. Please post your questions here
martindholmes
Posts: 131
Joined: Mon Aug 29, 2005 12:03 pm

Merging data from one TRichViewEdit into another

Post by martindholmes »

Hi there,

I'm having a problem figuring out how best to handle the merging of styles. I have two TRichViewEdit controls, each with a different default set of styles. I need to copy the contents of one into a location in the other. I'm doing this with

LoadRVFFromStreamEd

My problem is with how to handle the two sets of styles. I want to preserve the appearance of all the text which is being pasted into the target box, but I don't want to change the default set of styles in that box. As far as I can see, these are my options

rvf_sIgnore: when I choose this option, the text is not inserted for some reason. However, I don't think it's the right option anyway.

rvf_sInsertMap: This replaces the current styles in the target RVE with those from the RVF. That's not what I want at all.

rvf_sInsertMerge: Styles from RVF will be mapped to the most similar existing styles. New styles will not be added. This is not what I want either, because I need to preserve any styles in the incoming RVF which are not present in the target RVE.

I think what I need is something like what is available for RTF:

rvrsAddIfNeeded

which uses existing styles where they exist in the target RVE, but adds new ones if necessary. Is there any way to do this using InsertRVFFromStreamEd?

All help appreciated,
Martin
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Use InsertRVFFromStream (without "Ed", InsertRVFFromStreamEd is an editing method).

Example: http://www.trichview.com/forums/viewtopic.php?t=1196
martindholmes
Posts: 131
Joined: Mon Aug 29, 2005 12:03 pm

Post by martindholmes »

When I do that, nothing is pasted. This line works:

ufrmComments.rveFeedback.InsertRVFFromStreamEd(AStream);

But this line fails:

ufrmComments.rveFeedback.InsertRVFFromStream(AStream, ufrmComments.rveFeedback.TopLevelEditor.CurItemNo);


This is what populates the stream:

rveSnippets.SaveRVFToStream(AStream, False);
AStream.Position := 0;

Can you see any problem with this? Any idea why it's failing?

Thanks,
Martin
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

InsertRVFFromStream is not an editing method.
Before displaying, call ufrmComments.rveFeedback.Format.
And I think you want to add new text to the end, so call:

Code: Select all

ufrmComments.rveFeedback.InsertRVFFromStream(AStream,
  ufrmComments.rveFeedback.ItemCount); 
ufrmComments.rveFeedback.Format;
martindholmes
Posts: 131
Joined: Mon Aug 29, 2005 12:03 pm

Post by martindholmes »

I don't actually want to add new text at the end; I need to add it at the cursor position.

Cheers,
Martin
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Then use

Code: Select all

ufrmComments.rveFeedback.InsertRVFFromStreamEd(AStream); 
ufrmComments.rveFeedback must be formatted before this call. Calling Format after InsertRVFFromStreamEd is not needed (like any editing method, it formats the changed paragraphs itself)
martindholmes
Posts: 131
Joined: Mon Aug 29, 2005 12:03 pm

Post by martindholmes »

But that brings me back to my original problem: I can't get the behaviour I need when merging styles. Is there a way to use InsertRVFFromStreamEd with so that it behaves like "rvrsAddIfNeeded " for RTF?

Cheers,
Martin
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Your initial understanding of RVF style mapping options is not correct.

When loading RVF (LoadRVF or LoadRVFFromStream), in the both rvf_sInsertMap and rvf_sInsertMerge modes, styles are replaced.

However, when inserting RVF (InsertRVFFromStream, AppendRVFFromStream, InsertRVFFromStreamEd):
- rvf_sInsertMap - maps styles to the most similar existing styles; this is the analog of rvrsUseClosest for RTF.
- rvf_sInsertMerge - tries to reuse existing styles, adds new styles if necessary; this is the analog of rvrsAddIfNeeded for RTF.
martindholmes
Posts: 131
Joined: Mon Aug 29, 2005 12:03 pm

Post by martindholmes »

rvf_sInsertMerge is what I was using, but it's having an odd effect: it seems to replace the default style in the target RVE. Where styles have the same name in the two RVStyles, the style in the target would be overwritten by the style with the same name in the source. That's why I started looking for an alternative in the first place.

How should rvf_sInsertMerge behave when both the source and the target have styles with the same name, but which are actually different?

Cheers,
Martin
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Normally, names of styles are ignored when comparing styles on inserting.
If you included rvfoUseStyleNames in RVFOptions, exclude it.
martindholmes
Posts: 131
Joined: Mon Aug 29, 2005 12:03 pm

Post by martindholmes »

rvfo_UseStyleNames is False for both the source and the target RVE. RVFParaStylesReadMode and RVFTextStylesReadMode are both set to rvf_sInsertMerge.

This is the behaviour I see:
  • The default text style for the target RVE is Arial 10pt black.
    The default text style for the source RVE is Arial 10pt green bold.
    I insert the contents of the source RVE at the cursor position in the target, using InsertRVFFromStreamEd.
    The default text style for the target RVE is now 10pt green bold; even when I press return to get new paragraphs, 10pt green bold persists.
Is this what you'd expect to see?

Cheers,
Martin
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

This is the expected. The style at the caret position becomes current.
(unless you include rvprDoNotAutoSwitch in its Protection)
When you press Enter, a new paragraph inherits text and paragraph styles of the current paragraph (unless NextStyleNo and/or NextParaNo properties are defined)
martindholmes
Posts: 131
Joined: Mon Aug 29, 2005 12:03 pm

Post by martindholmes »

I have NextStyleNo and NextParaNo set to 0, so that the default style for the target RVE should be preserved, but that doesn't seem to make any difference.

Cheers,
Martin
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Please send me files necessary to reproduce this problem.
martindholmes
Posts: 131
Joined: Mon Aug 29, 2005 12:03 pm

Post by martindholmes »

I'll have to write a little demo app -- it's all embedded in a full-scale application at the moment.

Cheers,
Martin
Post Reply