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 delete the selection

Return Value

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

Description

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

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