PDFium Component Docs

FPdfAsync-yksikkö

Unit: FPdfAsync
Peruutustoken- ja future-apufunktiot pitkäkestoiselle PDFium-työlle, jonka on pysyttävä peruutettavana VCL- tai LCL-isännästä

Syntax

IPdfCancellationToken = interface
  function GetIsCancelled: Boolean;
  procedure ThrowIfCancelled;
  procedure RegisterCallback(const ACallback: TThreadMethod);
  property IsCancelled: Boolean read GetIsCancelled;
end;

IPdfCancellationTokenSource = interface
  function GetToken: IPdfCancellationToken;
  procedure Cancel;
  property Token: IPdfCancellationToken read GetToken;
end;

TPdfCancellationTokenSource = class(TInterfacedObject, IPdfCancellationTokenSource, IPdfCancellationToken)
  class function New: IPdfCancellationTokenSource; static;
end;

TPdfFutureWorker<T> = function(const AToken: IPdfCancellationToken): T of object;
TPdfFutureReply<T> = procedure(const AResult: TPdfFutureResult<T>) of object;
TPdfFutureThread<T> = class(TThread)
  constructor Create(const AWorker: TPdfFutureWorker<T>; const AReply: TPdfFutureReply<T>; const AToken: IPdfCancellationToken);
end;

TPdfFuture<T> = class
  class procedure Run(const AWorker: TPdfFutureWorker<T>; const AReply: TPdfFutureReply<T>; const AToken: IPdfCancellationToken = nil); static;
end;

Public Types

TypeDescription
EPdfOperationCancelledRaised by ThrowIfCancelled when a worker observes a cancellation request
EPdfOperationCancelled.CreateCreates the standard cancellation exception message used by token-aware workers
IPdfCancellationTokenRead-only worker-side token with IsCancelled, ThrowIfCancelled, and RegisterCallback
IPdfCancellationTokenSourceOwner-side source with Token and Cancel
TPdfCancellationTokenSourceDefault source and token implementation; create one with TPdfCancellationTokenSource.New
TPdfFutureStatusResult state: pfsSuccess, pfsCancelled, or pfsFailure
TPdfFutureResult<T>Completion envelope with Value, Status, ErrorMessage, and IsSuccess / IsCancelled / IsFailure
TPdfFutureWorker<T>Method-pointer callback that receives a cancellation token and returns the background result
TPdfFutureReply<T>Method-pointer callback that receives the completed TPdfFutureResult<T> on the host callback path
TPdfFutureThread<T>Thread implementation exposed for generic compiler compatibility; applications should use TPdfFuture<T>.Run instead
TPdfFuture<T>Generic helper that runs a worker on a background thread and posts completion to the main thread
PdfNoCancellationTokenShared token that never cancels, useful when an API requires a token but the caller has no cancel UI

Description

FPdfAsync keeps long-running render, export, and batch-processing code responsive without tying the library to one UI framework

Workers receive only IPdfCancellationToken, so they can poll IsCancelled, call ThrowIfCancelled, or register one callback without owning the cancel source

TPdfFuture<T>.Run wraps a worker result in TPdfFutureResult<T> and reports success, cancellation, and failure through one completion path

Example

var
  CancelSource: IPdfCancellationTokenSource;
begin
  CancelSource := TPdfCancellationTokenSource.New;
  TPdfFuture<Integer>.Run(Worker, Completed, CancelSource.Token);
  CancelSource.Cancel;
end;

See Also

TPdf.RenderPageProgressive, TPdfView.AsyncRendering