Trouble mixing .Text and .AsString

  • In a mailmerge routine, I need to delete full lines of text if besides a special code the line contains only spaces and tab characters, so I use the following routine.

    The problem is that although WPRtf1.Text is working as expected, it seems that after this routine, the RTF formatting is lost when rendering on screen (text color, bold, underline, etc).
    If I use WPRtf1.AsString, I can see all the RTF code plus my text, but that formatting is not rendered on screen, even if I am using ReformatAll to synchronize.

    • Offizieller Beitrag

    You cannot mix Text and AsString.

    But you can access the paragraphs in WPTools directly.

    Use
    WPRichText.Finder.Next( sCod ) to find the start text.

    You can read a := WPRichText.Finder..FoundPosition;

    Now you can find the end code.

    Get the position b and use SetSelPosLen( a, b-a )

    and call ClearSelection to delete the selection.

    If the text is inside only one paragraph or you just need marked paragraphs use

    par := FirstPar;
    while par<>nil do
    begin
    if par.HasText( sCod ) then
    par := par.DeleteParagraph
    else par : par.next;
    end;

  • Thank you for your information, you gave me the idea.
    As what I need is to delete the whole paragraph if certain conditions are met, I use .Text only for reading, and then, as you suggested, I use the par loop and par.DeleteParagraph

    • Offizieller Beitrag
    Zitat von psswp

    Thank you for your information, you gave me the idea.
    As what I need is to delete the whole paragraph if certain conditions are met, I use .Text only for reading, and then, as you suggested, I use the par loop and par.DeleteParagraph

    Please check out the method DeleteParWithCondition: