function ReplaceFormTextAndKeepSelection(const Text: WString): Boolean;
| Text | WString. Text written over the current selection of the focused field; pass an empty string to remove the selection |
Replaces the currently selected text inside whichever 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 mirrors 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 that PDFium never receives a nil buffer
On success the associated TPdf page scene is invalidated and the view repaints, so that 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 the ffReadOnly flagFormHandle directly rather than the AllowFormEvents-gated input path, so that 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');