Question about custom coloring

  • WPTools 6
    I create document templates with mail merge capabilities using your TWPRichText.InputMergeField method. I highlight these merge fields using the code such as:

    Code
    TWPRichText.AutomaticTextAttr.UseBackgroundColor := True;
    TWPRichText.AutomaticTextAttr.BackgroundColor := clYellow;


    I have a request to display different types of merge fields in different colors (basically, I use data from multiple databases in my mailmerge process-the request is for data from DB1 to appear one color & DB2 to appear in another).
    Is such a thing possible? Is so, how?

    • Offizieller Beitrag

    Hi,

    Yes, it is possible.

    OnGetAttrColor is triggered for text which uses a special
    style, for example a bookmark. It makes it possible to change the canvas attributes for the text output according to other conditions.

    This event is triggered frequentally, please make the handler fast.
    To activate the event set the UseOnGetAttrColorEvent flag in the
    properties for the special style (for example in property BookmarkTextAttr)

    Julian

  • Thanks Julian,

    Just so I am clear then...
    I currently have the AutomaticTextAttr properties set as I described earlier. This properly handles one of the two "types" of merge fields I am dealing with (the ones from DB1). If I use the event handler you mention, should I expect the settings defined in AutomaticTextAttr to be handled as my default settings and only have to add code for my "other" merge fields (those from DB2)?

    Or should I have to add code to the event handler to handle all situations? Something like:

    Code
    if <merge field from DB1> then
      CharStyle.TextColor := clYellow
    else if <merge field from DB2> then
      CharStyle.TextColor := clBlue;