Changing the background color behind a selected substring in a Firemonkey TMemo component

  

I wish to programmatically set focus on a particular substring in a (Delphi 10.3.1) Firemonkey TMemo component, by painting a yellow background behind the substring. The code below paints a yellow rectangle in the right position, but the rectangle appears to be superimposed over the text, thereby hiding it. Is there some TMemo property that can be used to avoid this? If not, what is the recommended fix?

procedure TTextGUIMemo.SetFocusOnHit(HitIndex: integer);
var
LineIndex: integer;
GlobalHitInterval: TIntegerArray2;
begin
FFileCptHitsExpd.FileCptHits.GetHitSubstringGlobal(HitIndex, {=>}LineIndex,
GlobalHitInterval);
FMemo.SetFocus;
FMemo.SelStart:= GlobalHitInterval[0];
FMemo.SelLength:= GlobalHitInterval[1];
FMemo.SelectionFill.Color := TAlphaColorRec.Yellow;
FMemo.FontColor:= TAlphaColorRec.Black;
FMemo.Repaint;
end;

Thank you in advance for any suggestions.

Comments are closed.