<< Click to display table of contents >>


Occurs while executing ApplyStyleConversion method.


  TRVStyleConversionEvent =

    procedure (Sender: TCustomRichViewEdit;

     StyleNo, UserData: Integer; AppliedToText: Boolean;

     var NewStyleNo: Integer) of object;


property OnStyleConversion:TRVStyleConversionEvent;

This event allows you to create custom conversion procedure of text styles for the selected text. This event is called for all selected text items allowing to change their text style.

It can be useful to implement commands like "make bold", "apply font", "change text color", etc.


StyleNo current text style (index in the collection of styles, Style.TextStyles);

UserData value passed as a parameter in ApplyStyleConversion;

AppliedToText True, if this event was called for conversion of style of text item; False, if it was called for conversion of the current text style (CurTextStyleNo);

NewStyleNo initially equals to StyleNo; assign a new value to this parameter to change text style.


Example 1

procedure TMyForm.MyRichViewEditStyleConversion(Sender: TCustomRichViewEdit;

  StyleNo, UserData: Integer; AppliedToText: Boolean;

  var NewStyleNo: Integer);


   if not (AppliedToText and

      (rvprStyleProtect in Style.TextStyles[StyleNo].Protection)) then

    NewStyleNo := UserData;


This example does exactly the same work as ApplyTextStyle, i.e. MyRichViewEdit.ApplyStyleConversion(StyleNo) will be equivalent to MyRichViewEdit.ApplyTextStyle(StyleNo).

You can see that ApplyStyleConversion ignores protection of styles. If you wish to protect them, you should check protection yourself and do not change this style (like in the example above).


Example 2

procedure TMyForm.MyRichViewEditStyleConversion(Sender: TCustomRichViewEdit;

                  StyleNo, UserData: Integer;

                  AppliedToText: Boolean;

                  var NewStyleNo: Integer);

var FontInfo: TFontInfo;


  // creating text style with the desired attributes

  FontInfo := TFontInfo.Create(nil);



    case UserData of


        if btnBold.Down then

          FontInfo.Style := FontInfo.Style+[fsBold]


          FontInfo.Style := FontInfo.Style-[fsBold];


        if btnItalic.Down then

          FontInfo.Style := FontInfo.Style+[fsItalic]


          FontInfo.Style := FontInfo.Style-[fsItalic];


        if btnUnderline.Down then

          FontInfo.Style := FontInfo.Style+[fsUnderline]


          FontInfo.Style := FontInfo.Style-[fsUnderline];


        FontInfo.FontName := FontName;


        FontInfo.Size     := FontSize;




        FontInfo.Color := ColorDialog1.Color;


        FontInfo.BackColor := ColorDialog1.Color;

      // add your code here....


    // searching for the style (or adding it if necessary)

    NewStyleNo := RVStyle1.FindTextStyle(FontInfo);





This example shows how to implement the following commands:

make bold/not bold,

make italic/not italic,

make underlined/not underlined,

change font name,

change font size,

apply font,

change text color,

change text background color.

In this code:

TEXT_*** – user defined integer constants with unique values; these constants identify commands; they are passed to ApplyStyleConversion as UserData;

RVStyle1 – TRVStyle component linked with the richview editor;

ColorDialog1: TColorDialog;

FontDialog1: TFontDialog;

btnBold, btnItalic, btnUnderline: TSpeedButton;

FontName: String;

FontSize: Integer.


See demos:

Demos\*\Editors\Editor 2\

See also:


See also methods: