function FormFieldZOrderAt(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 AcroForm widget annotations of the current page and reports the stacking position of the topmost one. The viewer first converts (X, Y) to page-space coordinates with DeviceToPage, which accounts for Zoom, Rotation, display mode, page padding and scroll offset, then calls PDFium's FPDFPage_FormFieldZOrderAtPoint with the page's form handle
A larger return value means the widget is stacked closer to the viewer, that is, drawn above fields with smaller values. Z-order here is the topmost hit-testing order of the annotation stack, not a widget index, so treat the values as opaque comparison numbers
Where a form widget and a link annotation overlap, compare this result with LinkZOrderAt: both values come from the same annotation stacking order, and the higher one identifies the annotation that PDFium treats as the hit at that pixel
The TPdf counterpart TPdf.FormFieldZOrderAtPoint(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 or the form environment is not initialised, 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 (FieldZ >= 0) and (FieldZ > LinkZ) then
Caption := 'form field wins the hit';
end;