TCustomRichViewEdit.OnParaStyleConversion

<< Click to display table of contents >>

TCustomRichViewEdit.OnParaStyleConversion

Occurs while executing ApplyParaStyleConversion method.

type

  TRVStyleConversionEvent = 

    procedure (Sender: TCustomRichViewEdit;

      StyleNo, UserData: Integer; AppliedToText: Boolean;

      var NewStyleNo: Integer) of object;

 

property OnParaStyleConversion:TRVStyleConversionEvent;

(introduced in version 1.7)

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

It can be useful for implementing commands like "change paragraph alignment", "change paragraph indents", etc.

Parameters:

StyleNo current paragraph style (index in collection of styles, Style.ParaStyles);

UserData value passed as a parameter in ApplyParaStyleConversion;

AppliedToText not used

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

 

Example:

procedure TMyForm.MyRichViewEditParaStyleConversion(

  Sender: TCustomRichViewEdit;

  StyleNo, UserData: Integer; AppliedToText: Boolean;

  var NewStyleNo: Integer);

var ParaInfo: TParaInfo;

begin

  // creating paragraph style with the desired attributes

  ParaInfo := TParaInfo.Create(nil);

  try

    ParaInfo.Assign(RVStyle1.ParaStyles[StyleNo]);

    case UserData of

      PARA_ALIGNMENT:

        ParaInfo.Alignment := GetAlignment;

      PARA_INDENTINC:

        begin

          ParaInfo.LeftIndent := ParaInfo.LeftIndent+20;

          if ParaInfo.LeftIndent>1000 then

            ParaInfo.LeftIndent := 1000;

        end;

      PARA_INDENTDEC:

        begin

          ParaInfo.LeftIndent := ParaInfo.LeftIndent-20;

          if ParaInfo.LeftIndent<0 then

            ParaInfo.LeftIndent := 0;

        end;

      PARA_COLOR:

        ParaInfo.Background.Color := ColorDialog1.Color;

      // add your code here....

    end;

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

    NewStyleNo := RVStyle1.FindParaStyle(ParaInfo);

  finally

    ParaInfo.Free;

  end;

end;

This example shows how to implement the following commands:

change paragraph alignment,

increase left indent,

decrease left indent,

change paragraph background color.

In this code:

PARA_*** user-defined integer constants with unique values; these constants identify commands; they are passed to ApplyParaStyleConversion as UserData;

RVStyle1 TRVStyle component linked with the MyRichViewEdit;

ColorDialog1: TColorDialog;

GetAlignment function returning paragraph alignment chosen by the user.

You can see that for new paragraph styles added in this event, Standard property is set to False. It is important, otherwise DeleteUnusedStyles will not be able to delete this style, even if all paragraphs of this style will be removed.

 

See demos:

Demos\*\Editors\Editor 2\

See also:

OnStyleConversion.

See also methods:

ApplyParaStyleConversion.