function LinkZOrderAt(X, Y: Integer): Integer;
| X, Y | Integer. Pixel coordinates relative to the viewer control, i.e. the coordinates the mouse events receive |
Hit-tests a screen pixel against the native link annotations of the current page and reports the stacking position of the topmost one. The viewer converts (X, Y) to page-space coordinates with DeviceToPage, honouring Zoom, Rotation, display mode, page padding and scroll offset, then calls PDFium's FPDFLink_GetLinkZOrderAtPoint on the page handle, the same native point test used by LinkAnnotationAtPos
A larger return value means the link is stacked closer to the viewer, that is, drawn above links with smaller values. Z-order here is the topmost hit-testing order of the annotation stack, not a link index, so treat the values as opaque comparison numbers
The test queries the page directly and needs no form environment, so it works even when the document carries no AcroForm and is not gated by AllowFormEvents. Where a link and a form widget overlap, compare this result with FormFieldZOrderAt: the higher value identifies the annotation that PDFium treats as the hit at that pixel
The TPdf counterpart TPdf.LinkZOrderAtPoint(X, Y: Double) wraps the same PDFium function. It takes page-space coordinates in Double directly and raises an exception when no page is active, whereas the TPdfView wrapper fails soft and returns -1
procedure TForm1.PdfView1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
FieldZ, LinkZ: Integer;
begin
FieldZ := PdfView1.FormFieldZOrderAt(X, Y);
LinkZ := PdfView1.LinkZOrderAt(X, Y);
if (LinkZ >= 0) and (LinkZ > FieldZ) then
Caption := 'link wins the hit';
end;