Page 1 of 1

Save/Load custom item types

Posted: Fri Mar 06, 2015 11:27 am
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.

Posted: Fri Mar 06, 2015 7:09 pm
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