Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Get a Mail-Merge Replace Pattern
See more Email Object Examples
Demonstrates the Chilkat Email.GetReplacePattern method, which returns a replacement pattern — the search string — previously defined for mail-merge operations with SetReplacePattern. The index is zero-based. This example defines two patterns and enumerates them.
Background: In Chilkat's mail-merge, each entry is a pattern (a placeholder token such as
FIRST_NAME) paired with a replacement string. GetReplacePattern retrieves the search side of the pair at a given index; GetReplaceString retrieves the matching replacement. Reading them back is useful for inspecting or logging exactly which substitutions will be applied when the message is sent.Chilkat Pascal (Lazarus/Delphi) Downloads
program ChilkatDemo;
// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.
{$IFDEF FPC}
{$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}
uses
{$IFDEF UNIX}
cthreads,
{$ENDIF}
SysUtils,
CkDllLoader,
Chilkat.Email;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
email: TEmail;
n: Integer;
i: Integer;
begin
// Demonstrates the GetReplacePattern method, which returns a replacement pattern (the
// search string) previously defined for mail-merge operations with SetReplacePattern.
// The index is zero-based.
email := TEmail.Create;
email.Subject := 'Hello FIRST_NAME';
email.Body := 'Dear FIRST_NAME, welcome to CITY.';
email.SetReplacePattern('FIRST_NAME','John');
email.SetReplacePattern('CITY','Denver');
n := email.NumReplacePatterns;
for i := 0 to n - 1 do
begin
WriteLn('Pattern ' + i + ': ' + email.GetReplacePattern(i));
end;
email.Free;
end;
// ---------------------------------------------------------------------------
begin
try
RunDemo;
except
on E: Exception do
WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
end;
WriteLn;
{$IFDEF MSWINDOWS}
WriteLn('Press Enter to exit...');
ReadLn;
{$ENDIF}
end.