ReplaceTokens

<< Click to Display Table of Contents >>

Navigation:  Programming > Mail Merge (replace fields with data) and data forms > Create Field >

ReplaceTokens

ReplaceTokens(const opening, closing: string; FieldPreText: string = ''): Integer;

 

This method (and its sister ReplaceTokensInAllTexts) updates the text and converts tokens such as <NAME>  into the respective field. The start and end character sequence is variable, you have to pass it to the function:   ReplaceTokens('<', '>');

 

The third parameter is the text which will be used to create the field name. You can use it to create fields such as "CUSTOMER.NAME" by using 'CUSTOMER.' as parameter FieldPreText.

 

ReplaceTokensInAllTexts does not only work in the current text but in all, header and footer texts.

 

Both function return the count of replacements.

 

Tip: WPTools 8 with the WPReporter addon also supports "Token to Template Conversion".

 

If you use the token to template conversion you can edit the mail-merge/reporting template with an editor such as MS Word.

 

The template is loaded into TWPRichText. In this control the template can be further edited with the additional convenience of syntax highlighting and on demand converted into a "true" reporting template. In case no bands are used, this technique can be also used to create mail merge templates. (WPTools' Reporting is backward compatible to mail merge)

 

Example:

rep_syntax_1