function ReplaceFormTextAndKeepSelection(const Text: WString): Boolean;
| Text | WString. Text written over the current selection of the focused field; pass an empty string to delete the selection |
Replaces the currently selected text inside whatever form widget currently owns the focus on the viewer's active page, by calling PDFium's FORM_ReplaceAndKeepSelection with the page's form handle
The replacement text stays selected after the call instead of collapsing the selection, so a following call can overtype or extend it again. This matches the typing model of a native text control and suits incremental, code-driven input such as IME composition or predictive text
Passing an empty string deletes the current selection; the wrapper passes a pointer to a NUL wide character so PDFium never receives a nil buffer
On success the associated TPdf page scene is invalidated and the view repaints, so the new field value becomes visible immediately
permFillForms or permModify permission, no widget owns the focus, or the focused widget sits on another pagefiTextField, or fiComboBox with the ffChoiceEdit flag, and it must not carry ffReadOnlyFormHandle directly rather than the AllowFormEvents-gated input path, so programmatic editing keeps working when user form input is switched off// Overtype the selected characters of the focused field,
// keeping the insertion selected for the next step
if PdfView1.FocusedFormFieldText <> '' then
PdfView1.ReplaceFormTextAndKeepSelection('NEW');