How to loop through selected paragraphs

  • Hello:

    I want to add a menu command where the user can select text with the mouse and then remove the formatting from it (both character attributes and paragraph styles). In particular, if the selection contains several paragraphs, I need to be able to either remove or change the parstyle that is assigned to them.

    I was thinking that if there was a .IsSelected property I could do something like this:

    Code
    {Clear text attributes}
      WPRichText1.SelectedTextAttr.ClearAttr(True, True);
    
      {Clear paragraph styles}
      par := WPRichText1.ActiveParagraph;
      while par.IsSelected do begin
        par.ABaseStyleName := '';   {or perhaps set it back to my default style}
        par.next;
      end;

    Is there some other way to do this?

    Thanks,

    Dale

    • Offizieller Beitrag

    Hi,

    You can use the callback CallForSelectedText.

    Example from unit WPCtrRich.pas:

    WPRichText.TextCursor.CallForSelectedText(Self, [], nil, nil, ULCharCallback, nil);

    procedure TWPCustomRichText.ULCharCallback(Sender: TObject;
    var CharItem: WideChar;
    par: TParagraph;
    posinpar: Integer;
    var Abort: Boolean);
    begin
    ....
    end;

    Julian