Hello Sergey,
I’ve been working with TRichView for a few weeks on an issue related to saving and reloading items efficiently. Despite valuable assistance from “Vector” (the name of my ChatGPT assistant), who extensively analyzed the help files and documentation, I am still struggling with the following problem:
Background:
In my project, I need to save RichViewEdit items in a custom format to minimize storage space(Not using the usual ways to save). I successfully iterated through all items (mainly of type TRVTextItemInfo) and mapped them using the following format:
ItemFormat := 'ItemText*TextStyleId*ParaStyleId*IsParaNewLine';
When saving to disk, I extract and store:
ItemText: The text of the item.
TextStyleId: The ID of the TextStyle in the RVStyle collection.
ParaStyleId: The ID of the ParaStyle in the RVStyle collection.
IsParaNewLine: A flag to indicate whether the item starts a new line.
Using these fields, I can reload the items and recreate the document using .AddNL() and .Add(). This works perfectly with predefined TextStyles stored in the RVStyle component.
The Issue:
When a user modifies a portion of text (e.g., by selecting it and changing the font size or other properties), new dynamic TextStyles are created in memory. These dynamic styles are saved correctly along with their TextStyleId.
However, when reloading the items, the original styling of these user-modified portions is lost. It appears that the RVStyle component does not retain or regenerate these dynamic styles during the reloading process.
What I’ve Tried:
I verified that the TextStyleId values of these dynamic styles are saved and reloaded correctly.
I attempted to reload the items while preserving their original dynamic styles, but it seems RVStyle cannot automatically recreate or apply the correct styles to match the original document.
I explored the use of StyleTemplates to simplify handling of dynamic styles but ran into challenges with mapping dynamically created styles back to their associated templates.
What I Need:
I would greatly appreciate guidance on the following:
How can I ensure that dynamically created TextStyles are properly saved and reloaded to retain their original formatting?
Is there a recommended approach to handle dynamic styles efficiently, especially in scenarios where user-modified text portions introduce new styles?
Could StyleTemplates simplify this process, and if so, how can I properly integrate them with dynamic TextStyles?
Your assistance would mean a lot to me as I’m striving to deliver a robust solution.
Thank you in advance for your support!
Best regards,
Bishara
Assistance Needed with Saving and Reloading Items in TRichViewEdit
-
- Site Admin
- Posts: 17632
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Re: Assistance Needed with Saving and Reloading Items in TRichViewEdit
Include rvfoSaveTextStyles and rvfoSaveParaStyles in RichViewEdit.RVFOptions.
Make sure that RichViewEdit.RVFTextStylesReadMode = RichViewEdit.RVFParaStylesReadMode = rvf_sInsertMerge.
With these settings, if you set RichViewEdit.UseStyleTemplates = True, StyleTemplates will be saved and loaded in RVF.
PS: RVF saves several text items having identical properties as one block of text. It may be more space-efficient than your format, if you store each item separately.
PPS: There are more flags that maybe useful to save:
- page break before this item
- does this item start a new paragraph (the break was added by ENTER) or a line inside a paragraph (the break was added by SHIFT+ENTER)
In RVF, these flags are stored as ItemOptions bitmask
Make sure that RichViewEdit.RVFTextStylesReadMode = RichViewEdit.RVFParaStylesReadMode = rvf_sInsertMerge.
With these settings, if you set RichViewEdit.UseStyleTemplates = True, StyleTemplates will be saved and loaded in RVF.
PS: RVF saves several text items having identical properties as one block of text. It may be more space-efficient than your format, if you store each item separately.
PPS: There are more flags that maybe useful to save:
- page break before this item
- does this item start a new paragraph (the break was added by ENTER) or a line inside a paragraph (the break was added by SHIFT+ENTER)
In RVF, these flags are stored as ItemOptions bitmask
Re: Assistance Needed with Saving and Reloading Items in TRichViewEdit
Thank you for your anseer.
I noticed a small issue with the AssignToStrings method in TRVStyleTemplateCollection. When AssignIds=True, the IDs are assigned to the Objects property but are not reflected in the Name. This can make it less clear when displaying the templates in a combo box or list.
I suggest appending the ID to the name (e.g., Name (ID: 123456)) when AssignIds=True to improve usability and clarity.
Thanks for your continuous support and updates to the library!
Best regards,
Bishara
I noticed a small issue with the AssignToStrings method in TRVStyleTemplateCollection. When AssignIds=True, the IDs are assigned to the Objects property but are not reflected in the Name. This can make it less clear when displaying the templates in a combo box or list.
I suggest appending the ID to the name (e.g., Name (ID: 123456)) when AssignIds=True to improve usability and clarity.
Thanks for your continuous support and updates to the library!
Best regards,
Bishara
-
- Site Admin
- Posts: 17632
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Re: Assistance Needed with Saving and Reloading Items in TRichViewEdit
StyleTemplateID is a value for internal use; it's not supposed to be displayed to the user.
Actually, StyleTemplateID is redundant, since names of style templates are unique by themselves. It was added for efficiency.
Actually, StyleTemplateID is redundant, since names of style templates are unique by themselves. It was added for efficiency.
Re: Assistance Needed with Saving and Reloading Items in TRichViewEdit
I believe a developer might need this feature. It is difficult to imagine how vital a feature like this could be for a developer when delving deep into TRichView code. Anyway, this was a simple task that I corrected in the original code to meet my needs.
Thank you again for your wonderful software.
Best regards,
Bishara
Thank you again for your wonderful software.
Best regards,
Bishara