Selection problem with TWPRichText

  • Hi,
    We try to do a sort of direct-mailing system.
    To do that, we have to duplicate data which are in a list like this :

    Code
    <begin list of code>   - <Code Name> : <Code Description><end list of code>

    If I have a 3 elements' list, the first thing that I would do is to copy the content of the list :

    Code
    <begin list of code>   - <Code Name> : <Code Description>   - <Code Name> : <Code Description>   - <Code Name> : <Code Description><end list of code>


    This is the code I'm using to copy the content of the list and to delete the start list tags and end list tags :

    Code
    AnsiString cpText;   int beginListPos = 0;   int endListPos = 0;    //find the last start list tag   while(wpDoc->Finder->Next(beginList))   {      beginListPos = wpDoc->Finder->FoundPosition;   }    //find the first end list tag   wpDoc->Finder->Next(endList);   endListPos = wpDoc->Finder->FoundPosition;   wpDoc->Finder->Clear();   int lg = endListPos - beginListPos - 7; //7 because of the length of the start list tag length    //select the text to copy   wpDoc->SetSelPosLen(debutListe + 6, lg, true); //6 because of the length of the start list tag length   cpText = wpDoc->SelectionAsString;    //delete the start list and end list tags   wpDoc->SetSelPosLen(beginListPos - 1, endListPos - beginListPos + 6, true);   wpDoc->ClearSelection(true);   for (int j = 0; j < 3; j++) //3 stand for the number of elements in the list    {      //paste the text      wpDoc->CPPosition= beginListPos - 1;      wpDoc->SelectionAsString = cpText;    }


    Is this the right way to do what I want to do? Do I use the right method?


    I also have a problem with this line :

    Code
    wpDoc->SetSelPosLen(beginListPos - 1, endListPos - beginListPos + 6, true);

    When I have only a list, it woks fine.
    But when I have 2 or more lists like this :

    Code
    <begin list of code>
        <begin 2nd list of code>
            - <Code Name> : <Code Description>
           - <Code Name> : <Code Description>
           - <Code Name> : <Code Description>
        <end 2nd list of code>
    <end list of code>


    it causes an EAccessViolation exception and I don't understand why...

    Thanks.

    • Offizieller Beitrag

    Hi,

    Use WPReporter - it is part of WPTools Bundle.

    It can use text with tokens and convert it into a reporting template.

    The syntax is described in the manual.

    I cannot recommend to use Find & replace to do it. It is comparatively slow.