<< Click to Display Table of Contents >> Navigation: Programming > Mail Merge (replace fields with data) and data forms > Create Field > Low Level |
If you work with TParagraph references You maybe want to create fields using low level routines.
There are two possibilities.
a) Use TParagraph.AppendNewObject
var starto, endo : TWPTextObj;
par : TParagraph;
begin
par := WPRichText1.ActiveParagraph;
starto := par.AppendNewObject(wpobjMergeField, true, false); // Start Object
par.Append('Julian Ziersch'); // Displayed Text
endo := par.AppendNewObject(wpobjMergeField, true, true); // End Object
// Link both objects together
endo.SetTag(starto.NewTag);
// Set Name of field
starto.Name := 'DB_NAME';
// Reformat and display
WPRichText1.ReformatAll(false, true);
end;
b) Use TParagraph.AppendNewObjectPair
var fieldo : TWPTextObj;
par : TParagraph;
begin
par := WPRichText1.ActiveParagraph;
fieldo := par.AppendNewObjectPair(wpobjMergeField, 'Julian Ziersch');
fieldo.Name := 'DB_NAME';
// Reformat and display
WPRichText1.ReformatAll(false, true);
end;
Using method (a) You can initialize the field with formatted text by subsequently adding text and changing the current writing mode between the text parts.