MergeField - Set RTF

  • How can i set an Edit or MergeField with a RTF Test?

    I insert the mergeField into a paragraph with

    fieldo := lastCell.AppendNewObjectPair(wpobjMergeField, 'x');

    Setting it to a normal text works with
    fieldo.EmbeddedText := 'NewText';
    but how can i set it to a rtf text, or insert a new TParagraph into the TWPTextObj so that the StartTag and EndTag works ...?

    Tried many things but nothing works.

    • Offizieller Beitrag

    You can select the field and assign the RTF text to SelectionAsString.

    If you use InputMergeField you can lave the cursor in the field and call LoadFromString to load the RTF text right at cursor position.

    Using RTF with fieldo := lastCell.AppendNewObjectPair(wpobjMergeField, 'x'); directly is not possible.

    or you use mailmerge and assign it to StringValue and also use mmMergeAsRTF in Contents.Options.

  • OK Thanks

    one another question

    if i directly Call the RichText.MergeText('', TRUE) after i added the AppendNewObjectPair(wpobjMergeField, fpItem.FieldName+'@ID'+IntToStr(sqlPos.FieldByName('ID').AsInteger));

    this field isn't filled.

    If i start the merge with a second button after the editfield is inserted, than it works

    Is there any function i have to call after inserting the fields?

  • hmmm i just tried some things ....

    This doesn't work :

    Code
    //WPRichText1.MergeText('', TRUE);    WPRichText1.ReformatAll(TRUE, TRUE);    WPRichText1.MergeText('', TRUE);    WPRichText1.ReformatAll(TRUE, TRUE);

    This works :

    Code
    WPRichText1.MergeText('', TRUE);
        //WPRichText1.ReformatAll(TRUE, TRUE);
    
    
        WPRichText1.MergeText('', TRUE);
        //WPRichText1.ReformatAll(TRUE, TRUE);

    What is the correct code?