[Help] Save style to ini file

General TRichView support forum. Please post your questions here
Post Reply
sliver80
Posts: 7
Joined: Sun Feb 05, 2006 11:04 am

[Help] Save style to ini file

Post by sliver80 »

hi, i need to save a runtime created style to an ini file.

my style has 3 textstyles and 3 parastyles (used for alignment), and i save it with:

StileRich->SaveINI(filename,index);

but it save all 3 textstyles, but noone parastyles.

and also...what should the index value be?



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

Post by Sergey Tkachenko »

I cannot reproduce this problem.
For example, I saved RVStyle from RichViewActions demo, and it worked fine. The saved ini-file contains the line

Code: Select all

ParasCount=3
and a number Para*=* lines.

Note that only properties with changed (not default) values are saved.
sliver80
Posts: 7
Joined: Sun Feb 05, 2006 11:04 am

Post by sliver80 »

hi,
the problem is that in the ini file i have all the textstyles information, but only ParasCount and ParaStyleName information of the parastyles, so i lost alignment information.

however i'll see the RichViewActions demo.

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

Post by Sergey Tkachenko »

I uses RichViewActions only because it's easy to test.
Ok, I created a new document in RichViewActions (one text and one paragraph style by default), added a text line, centered it (so the second, centered, paragraph style is added).
Saved to ini-file.
The following Para* lines are saved:

Code: Select all

ParasCount=2
ParaStyleName0=Left
ParaStyleName1=Left
ParaStandard1=0
ParaAlignment1=2
As you can see, two paragraph styles are saved. Both have name "Left" (because when RichViewActions creates a new style, it names it by its parent style), and you can see "ParaAlignment1=2" line, telling that the alignment of ParaStyles[1] is centered.
All as expected.
sliver80
Posts: 7
Joined: Sun Feb 05, 2006 11:04 am

Post by sliver80 »

problem solved !!! :D

i forgot to do:

"boxTemp->StileRich->ParaStyles->Add();"

before defining the Items[2] of ParaStyles and maybe the saveini doesn't save the 0 and 1 because go crazy.

thanks Sergey

ps: i don't understand why without ParaStyles->Add(), i haven't "List index out of bound" error.
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Collections of TextStyles and ParaStyles are special.
When accessing an out of bounds item, TextStyles.InvalidItem/ParaStyles.InvalidItem is returned, instead of raising an exception.
By default, TextStyles.InvalidStyles is white on red text, ParaStyles.InvalidItem has a red border.

It was implemented in this way because it's usually simpler to find an error in document generation if incorrect text is displayed in red than if the component generates an exception on formatting/drawing.
Last edited by Sergey Tkachenko on Sat Mar 11, 2006 5:37 pm, edited 1 time in total.
sliver80
Posts: 7
Joined: Sun Feb 05, 2006 11:04 am

Post by sliver80 »

great, it's a nice idea. :wink:

i really didn't think in this way and i masked like a stupid the red border (and before saveini problem it seem all ok) :oops:

thank a lot, sergey :wink:
Post Reply