Page 1 of 1

Copy and apply style button

Posted: Thu Jun 26, 2014 1:22 pm
by retwas
Hi

Does the button copy/apply style exist ?

Image

Thanks

Posted: Fri Jun 27, 2014 11:38 am
by Sergey Tkachenko
No, but I can explain how to save formatting and how to apply saved formatting.
Do you use StyleTemplates in your application?

Posted: Thu Jul 03, 2014 5:18 pm
by Steku
If you don't mind, I'm interested in how to do that. StyleTemplates are used.

Thanks, steku

Posted: Fri Jul 04, 2014 7:55 am
by retwas
Yes I use, I'm interessed to know :)

Posted: Sat Jul 05, 2014 7:28 pm
by Sergey Tkachenko
I can explain how to store the current text formatting and how to apply it to selected text.
This code stores only text formatting, without paragraph formatting.

You need two variables to store formatting:

Code: Select all

TextStyle: TFontInfo; 
StyleTemplateName: TRVStyleTemplateName;
Storing:

Code: Select all

var ST: TRVStyleTemplate; 

if TextStyle=nil then 
  TextStyle := TFontInfo.Create(nil); 
TextStyle.Assign(RVStyle1.TextStyles[RichViewEdit1.CurTextStyleNo]); 
ST := RVStyle1.StyleTemplates.FindItemById(TextStyle.StyleTemplateId); 
if ST<>nil then 
  StyleTemplateName :=  ST.Name 
else 
  StyleTemplateName :=  '';
Applying:

Code: Select all

var ST: TRVStyleTemplate; 

if TextStyle<>nil then begin 
  TextStyle.ParaStyleTemplateId := RVStyle1.TextStyles[RichViewEdit1.CurTextStyleNo]).ParaStyleTemplateId;  
  ST := RVStyle1.StyleTemplates.FindItemByName(StyleTemplateName); 
  if ST<>nil then 
    TextStyle.StyleTemplateId := ST.Id 
  else 
    TextStyle.StyleTemplateId := -1; 
  RichViewEdit1.ApplyTextStyle(RVStyle1.FindTextStyle(TextStyle)); 
end;
When the form is destroyed:

Code: Select all

TextStyle.Free;