Insert Paragraph in WPRichText

  • I am trying to copy the text of one WPRichText component into another using the following code:

    var
    TempPar: TParagraph;

    ...

    with WPRichText1 do
    begin
    TempPar := DBWPRTBlock.FirstPar;
    while ActiveText.AppendParCopy(TempPar, []) <> nil do ;
    end;

    This does copy in the paragraph, but it appends to the end of WPRichText1 instead of inserting into the current position I have set. What I want is to have my first WPRichText which could be like:

    This is a sentence.
    {B001}
    This is the rest of the document.

    The block {B001} would be loaded from another wprichtext component and copied in. Thus, if the B001 text was

    Some Name
    Some Address

    The result would be:

    This is sentence.
    Some Name
    Some Address
    This is the rest of the document.

    I don't seem to get this with the AppendParCopy. Is there a way to set the position before the copy is done? or should I use a different function?

    • Offizieller Beitrag

    Hi,

    AppendParCopy should be only used if the two TWPRichText use the same RTFDataProps object - if they are using a shared CharAttr chache, font tables, color tables and sztles.

    Otherwise insert the text with
    WP.SelectionAsString := WP2.AsString;

    Julian Ziersch

  • The inserting of the text now works great, but now I am back to a problem I posted about earlier. I am now using the code below to insert the block into the main richtext.

    with WPRichText do
    begin
    ActiveParagraph := InsertPar;
    SelectionAsString := DBWPRTBlock.AsString;
    ActiveParagraph.ASet(WPAT_IndentLeft, nIndexPos);
    end;

    where nIndexPos is the GetXPositionTw of the Cursor in the WPRichtext before the text gets copied in. However, when the text is merged in, it is always left aligned with the original left margin in WPRichText and not indented. I am not sure what other information you may need, but any ideas on a direction would be helpful. Keep in mind I only want the text of the block being inserted indented.