Identify paragraphs that contain selected text.

  • Delphi 5, Windows XP, WPTools v5.39 (yes, I know...May be this weekend)

    Assume a document with 8 paragraphs. User clicks in middle of third para and drags mouse to middle of 5th para. So, some text is selected in 3rd para, all in 4th para and some in 5th para.

    Question 1. How do I identify in code which paragraphs contain selected text? Using above example, code should identify para number 3, 4 and 5 as ones with selected text.

    Question 2. How do I change font properties of the ENTIRE para, not just the selected text? Using Example above, I want to toggle Strike-out font for ENTIRE text of Para 3, 4 and 5.

    The pseudo-code below shows what I need!

    As always, your help is greatly appreciated.

    JayM

    • Offizieller Beitrag

    Hi,

    You can use the callback "CallForSelectedText" of the WPRichText.TextCursor object:


    Here You can pass a function pointer to a method which should be called for each of the paragraphs.

    Inside the method You only need to assign a new CharAttr to the complete text.

    The WPRichText.AttrHelper calculates a CharAttr index value for You.

    Code
    procedure TWPTBXForm.CallForAllSelectedPar(    Sender: TObject;    par: TParagraph;    IsParent: Boolean;    FromChar, ToChar: Integer;    var Abort: Boolean);var i : Integer;begin   for i:=0 to par.CharCount do       par.CharAttr[i] :=  WPRichText1.AttrHelper.CharAttr;end;

    Call this like this:

    Code
    WPRichText1.AttrHelper.Clear;
        WPRichText1.AttrHelper.SetFontName('Courier New');
        WPRichText1.AttrHelper.SetFontSize(12);
        WPRichText1.TextCursor.CallForSelectedText(self, [], CallForAllSelectedPar, nil, nil, nil);
        WPRichText1.ReformatAll(true, true);

    Regards,

    Julian