Changing style on runtime issue.

General TRichView support forum. Please post your questions here
Post Reply
friman
Posts: 25
Joined: Fri Jul 17, 2015 4:26 am

Changing style on runtime issue.

Post 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!
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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)
Post Reply