{"id":95,"date":"2007-05-12T13:55:15","date_gmt":"2007-05-12T11:55:15","guid":{"rendered":" http:\/\/www.nsonic.de\/blog\/2007\/05\/change-richedit-without-moving-the-cursor\/"},"modified":"2007-05-12T13:55:16","modified_gmt":"2007-05-12T11:55:16","slug":"change-richedit-without-moving-the-cursor","status":"publish","type":"post","link":"https:\/\/www.nsonic.de\/blog\/2007\/05\/change-richedit-without-moving-the-cursor\/","title":{"rendered":"Change RichEdit without moving the Cursor"},"content":{"rendered":"<p><em>><br \/>\n> I&#8217;m trying to trim any spaces at the end of a line in a TRichEdit after<br \/>\n> the cursor moves off the line. I can detect when the cursor moves, and<br \/>\n> I can trim the line &#8211; the problem is, when I update the line<br \/>\n> (MyRichEdit.Lines[PreviousLine] := MyString) the cursor pops back to the<br \/>\n> line that has been trimmed. Any way to prevent this?<br \/>\n><br \/>\n<\/em><br \/>\nYou have to save and restore the caret position yourself, e.g.<\/p>\n<p>[code lang=&#8221;delphi&#8221;]procedure TForm1.Button1Click(Sender: TObject);<br \/>\nvar<br \/>\ntemp : integer ;<br \/>\noldlen: integer;<br \/>\ns: string;<br \/>\nbegin<br \/>\nwith richedit1 do begin<br \/>\ntemp:= selstart;<br \/>\ns:= lines[0];<br \/>\noldlen := Length( S );<br \/>\nS := Trim( S );<br \/>\nlines[0] := S;<br \/>\nselstart := temp &#8211; oldlen + length( S );<br \/>\nend;<br \/>\nend;<br \/>\n[\/code]<br \/>\nPeter Below (TeamB)<br \/>\n100113.1101@compuserve.com <\/p>\n<p>)<br \/>\nNo e-mail responses, please, unless explicitely requested!<\/p>\n<p>[tags]Delphi, Components, RichEdit[\/tags]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>> > I&#8217;m trying to trim any spaces at the end of a line in a TRichEdit after > the cursor moves off&hellip;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":""},"categories":[11],"tags":[90,75,93],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p71Tml-1x","_links":{"self":[{"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/posts\/95"}],"collection":[{"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/comments?post=95"}],"version-history":[{"count":0,"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/posts\/95\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/media?parent=95"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/categories?post=95"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/tags?post=95"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}