function GetLinkedAnnotationChain(AnnotIndex: Integer; Relationship: TPdfAnnotationRelationship; MaxDepth: Integer = 64): TPdfIntegerArray;
| AnnotIndex | Integer. Zero-based index of the starting annotation on the current page, in the range 0 .. AnnotationCount - 1 |
| Relationship | TPdfAnnotationRelationship. parPopup follows the /Popup entries; parInReplyTo follows the /IRT reply entries |
| MaxDepth | Integer. Maximum number of links to follow. Must be between 1 and 4096, otherwise an EPdfError is raised. The default is 64 |
| Result | TPdfIntegerArray. Page indexes of the linked annotations in visit order. Empty when the starting annotation has no such link |
Repeatedly applies GetLinkedAnnotationIndex: from the starting annotation it follows the requested relationship to the next annotation, then again from that one, collecting each index along the way. The result is the reply thread of a discussion, or a popup chain, as a plain array of page annotation indexes
The walk stops on three conditions: the current annotation has no further link, the number of visited links reaches MaxDepth, or the next index would revisit an annotation already seen (the starting index counts as seen). The cycle guard makes the call safe on malformed documents whose /IRT entries loop
The starting index itself is never part of the result — only the annotations it leads to. An annotation without the requested link yields an empty array, not an error
MaxDepth outside 1 .. 4096 raises an EPdfError before any annotation is opened
var
Chain: TPdfIntegerArray;
Index: Integer;
begin
// collect the whole reply thread under annotation 5
Chain := Pdf1.GetLinkedAnnotationChain(5, parInReplyTo);
for Index in Chain do
Memo1.Lines.Add(Pdf1.Annotation[Index].ContentsText);
end;