bk31415 0 Posted 8 hours ago (edited) This is sample code: procedure TForm1.Button1Click(Sender: TObject); const CRLF = #13#10; var Text1: String; Pos1: Integer; begin Text1 := '[' + CRLF; Text1 := Text1 + '{' + CRLF; Text1 := Text1 + '"country":"AD",' + CRLF; Text1 := Text1 + '"name":"Sant Julià de Lòria",' + CRLF; Text1 := Text1 + '"lat":"42.46372",' + CRLF; Text1 := Text1 + '"lng":"1.49129"' + CRLF; Text1 := Text1 + '},' + CRLF; Text1 := Text1 + '{' + CRLF; Text1 := Text1 + '"country":"AD",' + CRLF; Text1 := Text1 + '"name":"Pas de la Casa",' + CRLF; Text1 := Text1 + '"lat":"42.54277",' + CRLF; Text1 := Text1 + '"lng":"1.73361"' + CRLF; Text1 := Text1 + '},' + CRLF; Text1 := Text1 + '{' + CRLF; Text1 := Text1 + '"country":"AD",' + CRLF; Text1 := Text1 + '"name":"Ordino",' + CRLF; Text1 := Text1 + '"lat":"42.55623",' + CRLF; Text1 := Text1 + '"lng":"1.53319"' + CRLF; Text1 := Text1 + '},' + CRLF; Text1 := Text1 + '{' + CRLF; Text1 := Text1 + '"country":"AD",' + CRLF; Text1 := Text1 + '"name":"les Escaldes",' + CRLF; Text1 := Text1 + '"lat":"42.50729",' + CRLF; Text1 := Text1 + '"lng":"1.53414"' + CRLF; Text1 := Text1 + '}' + CRLF; Text1 := Text1 + ']'; {26 lines} Pos1 := Pos('Ordino', Text1); Memo1.Lines.Text := Text1; Memo1.SelStart := Pos1; Memo1.SelLength := Length('Ordino'); Memo1.SetFocus; end; When I run this, I expect Memo1.SelText to be 'Ordino' but the actual selected text turns out to be 'rdino"'. I am baffled why it shifts 1 char right. Could someone explain why. Edited 7 hours ago by bk31415 Share this post Link to post
Stefan Glienke 2133 Posted 7 hours ago Because Pos is 1-based while SelStart is 0-based. You could have read the documentation: https://docwiki.embarcadero.com/Libraries/Athens/en/System.Pos https://docwiki.embarcadero.com/Libraries/Athens/en/Vcl.StdCtrls.TCustomEdit.SelStart Share this post Link to post
bk31415 0 Posted 7 hours ago I led myself to think the reason to be more complex --like count of CRLF's etc. But, 0/1-base issue never occured to me. Thank you. Share this post Link to post