Hello All,
Just to add for completeness:
To fix your code copy the files "FMX.Platform.UI.Android" & "FMX.Presentation.Android.Style" into your project folder.
Open "FMX.Platform.UI.Android" and search for "procedure TTextServiceAndroid.InternalUpdateSelection;"
Replace this procedure with the following:
procedure TTextServiceAndroid.InternalUpdateSelection;
var
SelStart, SelEnd: Integer;
begin
if FTextView = nil then
Exit;
CalculateSelectionBounds(SelStart, SelEnd);
// Fixes issue with enter key in TMemo - https://en.delphipraxis.net/topic/12197-delphi-122-tmemo-indexoutofbounds/?tab=comments#comment-95629
// This is the orginal code
// if SelEnd - SelStart > 0 then
// FTextView.setSelection(SelStart, SelEnd)
// else
// FTextView.setSelection(CaretPosition.X);
if SelEnd - SelStart > 0 then
FTextView.setSelection(SelStart, SelEnd)
else if CaretPosition.X > JCharSequenceToStr(FTextView.getText).Length then
FTextView.setSelection(JCharSequenceToStr(FTextView.getText).Length)
else
FTextView.setSelection(CaretPosition.X);
end;
The underlying issue is that when you press the enter key at the end of the line on a TMEMO "CaretPosition.X" is returning 1 character more than the length of the actual string in the memo. The fix just checks if "CaretPosition.X" is longer than the length and if it is it move the caret to the "Length".