Sample code for 30+ languages & platforms
Pascal (Lazarus/Delphi)

Monitor and Cancel a Running DKIM Operation

See more DKIM / DomainKey Examples

Demonstrates the Chilkat Dkim.HeartbeatMs and Dkim.AbortCurrent properties, which monitor and cancel a long-running operation such as a DNS public-key lookup. HeartbeatMs sets how often an AbortCheck event fires, and AbortCurrent requests cancellation.

Background: Most Dkim work is instant, but anything touching DNS can stall on a slow or unresponsive server. HeartbeatMs makes the object emit a periodic AbortCheck callback during such calls so an application stays responsive and can show progress, and AbortCurrent — set from that callback or from another thread — breaks a blocked synchronous call out early. Together they turn an otherwise uninterruptible operation into a cancellable one.

Chilkat Pascal (Lazarus/Delphi) Downloads

Pascal (Lazarus/Delphi)
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.Dkim;

// ---------------------------------------------------------------------------

procedure RunDemo;
var
  success: Boolean;
  dkim: TDkim;

begin
  success := False;

  //  Demonstrates the Dkim properties HeartbeatMs and AbortCurrent, which monitor and cancel a
  //  long-running operation such as a DNS public-key lookup.

  dkim := TDkim.Create;

  //  Fire an AbortCheck event callback every 100 ms during method calls.  In programming languages
  //  where Chilkat supports event callbacks, the callback can request cancellation.
  dkim.HeartbeatMs := 100;

  //  AbortCurrent may be set to True to request cancellation of a running operation.  It is
  //  typically set from another thread, or from within an AbortCheck callback.  Setting it False
  //  here ensures the operation is not pre-emptively aborted.
  dkim.AbortCurrent := False;

  //  PrefetchPublicKey performs a synchronous DNS lookup, which HeartbeatMs monitors and
  //  AbortCurrent can cancel.
  success := dkim.PrefetchPublicKey('myselector','example.com');
  if (success = False) then
    begin
      WriteLn(dkim.LastErrorText);
      Exit;
    end;
  WriteLn('Public key prefetched.');


  dkim.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.