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?