Delphi DLL
Delphi DLL
Get a Mail-Merge Replacement String by Index
See more Email Object Examples
Demonstrates the Chilkat Email.GetReplaceString method, which returns the replacement string for the Nth previously-defined pattern/replacement pair (a mail-merge feature). The index is zero-based and corresponds to the same index used by GetReplacePattern. This example defines two pairs and prints each pattern with its replacement.
Background: Pairing
GetReplacePattern (the token to find) with GetReplaceString (the text to substitute) at the same index lets you walk the full mail-merge table. Retrieving a replacement by its position is handy when enumerating all substitutions; to look one up by its pattern instead, use GetReplaceString2.Chilkat Delphi DLL Downloads
var
email: HCkEmail;
n: Integer;
i: Integer;
begin
// Demonstrates the GetReplaceString method, which returns the replacement string for the
// Nth previously-defined pattern/replacement pair (a mail-merge feature). The index is
// zero-based and corresponds to the same index used by GetReplacePattern.
email := CkEmail_Create();
CkEmail_putSubject(email,'Hello FIRST_NAME');
CkEmail_putBody(email,'Dear FIRST_NAME, welcome to CITY.');
CkEmail_SetReplacePattern(email,'FIRST_NAME','John');
CkEmail_SetReplacePattern(email,'CITY','Denver');
n := CkEmail_getNumReplacePatterns(email);
for i := 0 to n - 1 do
begin
Memo1.Lines.Add(CkEmail__getReplacePattern(email,i) + ' -> ' + CkEmail__getReplaceString(email,i));
end;
CkEmail_Dispose(email);