Page 1 of 1

Changing style on runtime issue.

Posted: Wed Aug 19, 2015 2:36 pm
by friman
Hello, I want to set style per item dinamically, for example

Code: Select all

  Style.TextStyles[3].Size:=TextSize;
  Style.TextStyles[3].Color:=TextColor;
  Style.TextStyles[3].HoverColor:=TextColor;
  AddWithURLS('Text example',3,6);
  RichView1.FormatTail;
  RichView1.Update;
It retrieve the values, but affect all previous items
What I doing wrong?

Thanks on advance!

Posted: Thu Aug 20, 2015 7:30 am
by Sergey Tkachenko
Yes, if you change properties of existing text styles, it affects all text items linked to this style.
The correct way is searching for the style with the desired properties. If it already exists, use this text style. If not, add a new style to the end of TextStyles.
This work can be done using FindTextStyle method.

For example

Code: Select all

var TextStyle: TFontInfo;
  StyleNo: Integer;

TextStyle := TFontInfo.Create(nil);
TextStyle.Assign(Style.TextStyles[0]);
TextStyle.Size := TextSize;
TextStyle.Color := TextColor;
TextStyle.HoverColor := HoverColor;
StyleNo := Style.FindTextStyle(TextStyle);
TextStyle.Free;
Now you can use StyleNo, it refers to a style having necessary properties.

I recommend to study these demos:
http://www.trichview.com/forums/viewtopic.php?t=63
(as far as I remember, they were created before introducing RVStyle.FindTextStyle, they use a more complicated way RVStyle.TextStyles.FindSuchStyle, but the idea is the same)