Doing some simple inserting.

  • Hello,

    I have seem to have hit a roadblock while trying to do some simple inserting. I can only assume I'm going about this the wrong way, but I've run out of good ideas on how to do this programmatically.

    I have two TWPRichText components and each with multiple pages worth of content. For this scenario, I will need to insert the contents of page 2 from my first document in-between the the contents of pages 4 and 5 in my second.

    For copying the page, I do not want to copy the headers, so I'll get the body datablock.

    Code
    FControl1.RTFData.Find(wpIsBody, wpraOnAllPages);

    When trying to copy paragraphs from one document to the other, my NextPar and PrevPar properties are always nil. This is whether I'm using the body's StartPar.NextPar or using the page's StartPar.NextPar. This prevents me from successfully copying any more than the first paragraph of the page.

    I will gladly look at a demo if you have a recommendation, but the only relevant demos I found were for appending a whole block of text, not necessarily for inserting/copying a page of text.

    Thanks,
    -Nathan

    • Offizieller Beitrag

    Hi,

    If you copy paragraph objects you need synchronized editors. Only then the attributes will be preserved. See demo GlobalStyle which shows how to set up this editors.

    It is also not "simple" to copy a page. The text is not sparated into pages, but into paragraphs. The text of paragrapghs is distributed on pages. It is possible to use some text on seveal pages at the same time.

    If you want to copy one page from editor 1 to editor 2 You can use use the method

    function GetPagesAsString(frompage, topage: Integer; const format: string = 'ANSI'): string;

    and load the text into the destination editor.

    Here it is not guaranteed that in the destination page 3 will become page 4 etc. It can become page 5.

    Zitat

    When trying to copy paragraphs from one document to the other, my NextPar and PrevPar properties are always nil. This is whether I'm using the body's StartPar.NextPar or using the page's StartPar.NextPar. This prevents me from successfully copying any more than the first paragraph of the page.

    You need to copy paragraphs as You loop through the page text (You seem to knwo what this is). And then you set par.NextPar always to the next copied instance.

    This will create a paragraph list which can be inserted at the destination (if the editors are synchronized).

    Julian