Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Count the Replace Patterns Set on an Email
See more Email Object Examples
Demonstrates the read-only Chilkat Email.NumReplacePatterns property, which returns how many replacement patterns have been set via SetReplacePattern. When replacement patterns are present, the email bodies and header fields are modified by applying the search/replacement strings during the sending process. Pattern indexes are zero-based. This example sets two patterns and prints the count.
Background: This is Chilkat's built-in mail merge. You compose one email containing placeholder tokens (for example
FIRST_NAME or CITY), register each token and its replacement with SetReplacePattern, and the substitutions are applied when the message is sent — letting you personalize a bulk mailing without building a separate message for every recipient.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;
begin
// Demonstrates the read-only Email.NumReplacePatterns property. Replace patterns are
// search/replacement strings (set with SetReplacePattern) that are applied to the email
// bodies and header fields during mail-merge sending. Indexes are zero-based.
email := TEmail.Create;
email.Subject := 'Hello FIRST_NAME';
email.Body := 'Dear FIRST_NAME, your order ships to CITY.';
email.SetReplacePattern('FIRST_NAME','John');
email.SetReplacePattern('CITY','Denver');
WriteLn('NumReplacePatterns = ' + email.NumReplacePatterns);
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.