TTMSFMXRichEditor and mergefields

Using reText.Caret.CharIndex is the index of the character within the selected text element. To get the absolute caret position, use richeditor.SelStart.

Example:


var
  ss: integer;
  txt: string;
  l: integer;
begin
  txt := 'test';
  l := Length(txt);
  ss :=   richeditor1.SelStart;
  richeditor1.InsertText(txt);

  // reset to orig. caret position
  richeditor1.SelStart := ss;
  richeditor1.SelLength := l;
  richeditor1.SetSelectionMergeField('mergename');
end;