Save/Load custom item types

General TRichView support forum. Please post your questions here
Post Reply
johnF
Posts: 27
Joined: Mon Feb 02, 2015 4:41 pm

Save/Load custom item types

Post by johnF »

Hi,

I'm using SaveRVFToStream and InsertRVFFromStream to insert the contents of a RichView into a RichViewEdit. However my custom item type (TRVLabelItemInfo descendent) vanishes.

I've also tried SaveRVF and LoadRVF and it vanishes.

What do I have to do so that it my TRVLabelItemInfo descendent?

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

Post by Sergey Tkachenko »

1) Make sure that you assigned an unique negative constant to StyleNo property.
2) Override the virtual constructor Create and assign StyleNo there.
If you have other constructors, assign this property in them too.
3) Register your item class by calling RegisterRichViewItemClass.
You can find examples in Demos\Addins\

By the way, if you add new properties to items, the best way is to organize them as "extra integer properties" or "extra string properties", overriding the following methods (for integer properties):
- GetRVFExtraPropertyCount
- SaveRVFExtraProperties
- SetExtraCustomProperty
- SetExtraIntPropertyEx
- GetExtraIntPropertyEx
- GetExtraIntPropertyReformat.
(all methods are self-explanatory except for the last one; GetExtraIntPropertyReformat returns a value specifying the operation to perform when this property is changed as an editing operation: do nothing, reformat paragraph, reformat the whole document, do nothing in TRichViewEdit but repaint if in ScaleRichView, do nothing in TRichViewEdit but full reformat if in ScaleRichView)

As an example, you can see how rveipcPageNumberType is implemented in RVFieldItems.pas.
These methods are easy to implement, and you will get:
- saving and loading these properties to RVF without writing additional code
- ability to change these properties as an editing (undoable) operations using SetCurrentItemExtraIntPropertyEx
Post Reply