Change Attribute of bookmarked text

  • Q: In our current code, we need to change the font style of the bookmark embedded text.

    A: To do this most effectively you can use this code:

    add an event handler for OnMailMergeGetText

    1. procedure TForm1.WPRichText1MailMergeGetText(Sender: TObject;
    2. const inspname: string; Contents: TWPMMInsertTextContents);
    3. begin
    4. if Contents.StartInspObject.ObjType=wpobjBookmark then
    5. begin
    6. TWPRichText(Sender).CurrAttr.BKColor := TWPRichText(Sender).CurrAttr.ColorToNr(clYellow, true);
    7. TWPRichText(Sender).CurrAttr.Color := TWPRichText(Sender).CurrAttr.ColorToNr(clRed, true);
    8. TWPRichText(Sender).CurrAttr.AddStyle([afsBold]);
    9. end;
    10. end;

    and make this event beeing called for each bookmark: