Change Attribute of bookmarked text

Problem + Solutions with the modern WPTools architecture which was introduced with WPTool 5
wpsupport
Site Admin
Posts: 7384
Joined: Fri Oct 24, 2003 4:06 pm
Contact:

Change Attribute of bookmarked text

Postby wpsupport » Tue Oct 06, 2015 7:04 am

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

Code: Select all

procedure TForm1.WPRichText1MailMergeGetText(Sender: TObject;
  const inspname: string; Contents: TWPMMInsertTextContents);
begin
  if Contents.StartInspObject.ObjType=wpobjBookmark then
  begin
      TWPRichText(Sender).CurrAttr.BKColor := TWPRichText(Sender).CurrAttr.ColorToNr(clYellow, true);
      TWPRichText(Sender).CurrAttr.Color := TWPRichText(Sender).CurrAttr.ColorToNr(clRed, true);
      TWPRichText(Sender).CurrAttr.AddStyle([afsBold]);
  end;
end;


and make this event beeing called for each bookmark:

WPRichText1.MergeTextEx('','',wpobjBookmark,[wpmergeAllTexts]);

Return to “FAQ WPTools 5, 6 and 7 - General”



Who is online

Users browsing this forum: No registered users and 4 guests