Copy a specific paragraph between two TWPRichText components

  • In the pre-WP5 days, to copy over a specific paragraph from, say, wprtfSource to wprtfDest, code like this might be used

    Code
    lin := wprtfSource.Memo.Active_paragraph^.line;
    repeat
      wprtfDest.FastAppendActiveLine( wprtfSource );
      lin := lin^.next;
    until( lin = nil );


    This would copy over all text and embedded objects, including graphics. Because FastAppendActiveLline worked with a line at a time, the code needs to iterate through the "line chain".

    Now, with WPTools 5, what's the "preferred" way to do this - copy over a specific paragraph, the active one, from the source to the destination TWPRichText component, and bring along all embedded TextObjects as well?

    diamond

    • Offizieller Beitrag

    If you need a low level routine to copy one paragraph and all the included paragraphs (this can be table rows or table cells) to the destination editor use AppendParCopy:

    Code
    var par : TParagraph;begin  // Get the reference to current paragraph  par := WPRichText1.ActiveParagraph;  // Append it to the active RTFDataBlock  DestWP.ActiveText.AppendParCopy(par);  // This moves to the next paragraph! Useful in a loop!  WPRichText1.ActiveParagraph := par;  // Format is required sometimes later  DestWP.DelayedReformat;end;

    For better understanding I copy the AppendParCopy source from the RTF-Engine:

    You can see from this code that this routine tries to add new table rows to a table object which already exists in the text. So instead of moving the complete table you can also copy only selected rows. Since the result value of the AppendParCopy function is the new paragraph you can also do some pro-processing, for example apply certain attributes.

    You can also use the SET parameter SkipObjects to leave out certain object types, such as [wpobjMergeField] to ignore mail merge fields (the contained text will be copied of course).

    I hope this helps,
    Julian Ziersch

    BTW - WPTools 5 usually does not work with 'lines'. Although it is possible to get the lines as they are currently used by the rendering module, in the main memory (RTFDataBlock) there are no lines.

  • This seems to work for copying. I need to do it line by line really because sometimes I will append something to the line.

    How can I prevent it from entering a blank line at the top? I think it's becuase there is already a blank paragraph in the destination, but it creates a new one instead of adding to that one. If I try to clear the dest rtf first, I get an AV.