AttachComponent

Document parts, variable data, document editing

Description

Replaces the initial and current component snapshots of a TPDFlibDynamicComponentSession with fresh clones of a caller-owned component and clears all progress state

Syntax

Function TPDFlibDynamicComponentSession.AttachComponent(
  AComponent: TPDFlibDynamicComponent): Integer;

Parameters

AComponentCaller-owned component whose CloneComponent supplies both the new initial and the new current snapshot

Remarks

Both clones are created before any stored snapshot is released, so a CloneComponent that returns Nil leaves the previous component, composition count, completion flag and retry state untouched

On success the session frees its old snapshots, stores the new pair and resets CompositionCount to zero, Completed, KeepTogetherRetryPending, LastRetryReason and LastRequiredSlotHeight

The session never takes ownership of AComponent; only the clones are stored, so the caller keeps and frees the passed instance independently

The session constructor calls AttachComponent, so a session created with a Nil or uncloneable component starts without usable snapshots

Example

Replacement := TNumberedPagesComponent.Create(1, 5);
try
  if Session.AttachComponent(Replacement) = 1 then
    Status := Session.ComposeNext(PageNumber, 36, 36, 540, 720,
      Placement);
finally
  Replacement.Free;
end;

Return values

1Both clones were created and committed as the new initial and current snapshots with all progress state cleared
0AComponent is Nil or one of the CloneComponent calls returned Nil, and the previous snapshots and state are preserved

See also

TPDFlibDynamicComponentSession, TPDFlibDynamicComponent, CloneComponent, CloneCurrentComponent, ComposeNextLayout