Range check error in VCL.TMSFNCRichEditor

There is a bug that triggers a range check error in VCL.TMSFNCRichEditor.pas if range checking is set:


The function getcharpos should be modified as follow to elimitate the error:

function TTMSFNCRichEditor.GetCharPos(AValue: string; CharIndex: integer): integer;
var
  nnfit,mw: integer;
  charpos: array[0..2047] of integer;
  sz: TSize;
begin
  if Assigned(Caret.Element) then
  begin
    if (Caret.Element is TTextElement) then
      Canvas.Font.Assign((Caret.Element as TTextElement).Font)
    else
      Canvas.Font.Assign(Font);

    Canvas.Font.Size := Round(Canvas.Font.Size * FZoomFactor);
  end;

  mw := GetLineWidth;
  GetTextExtentExPoint(Canvas.Handle, PChar(AValue + ' '), Min(2047,Length(AValue) + 1), mw, @nnfit, @charpos, sz);

  if (charindex > 2047)  then
    charindex := 2047;
  // fix range check error
  if charindex < 1 then
    charindex := 1;
  // end fix
  Result := charpos[CharIndex - 1];
end;


Could you please amend the original code?

Quick addition: to trigger the original bug, you must, of course, have the "range check error" compiler option set.

This bug still hasn't been fixed in the latest version

We can confirm this will be synchronized in TMS FNC UI Pack v2.2.1.0

Thanks