PDFium Delphi Component Docs

ReplaceFormTextAndKeepSelection method

Component: TPdfView  ·  Unit: PDFium
Replaces the selected text of the currently focused form field and keeps the replacement selected

Syntax

function ReplaceFormTextAndKeepSelection(const Text: WString): Boolean;

Parameters

TextWString. Text written over the current selection of the focused field; pass an empty string to remove the selection

Return Value

Boolean. True when an editable form text widget owns the focus on the active page and the replacement was carried out; False when the call is a no-op

Description

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

Remarks

Example

// Overtype the selected characters of the focused field,
// keeping the insertion selected for the next step
if PdfView1.FocusedFormFieldText <> '' then
  PdfView1.ReplaceFormTextAndKeepSelection('NEW');

See Also

GetSelectedFormText, SelectAllFormText, PasteFormTextFromClipboard, CutSelectedFormTextToClipboard, CopySelectedFormTextToClipboard, FormUndo, FocusedFormFieldText