«« Site Rescued »»

While the site is still going to move from its current host, a new site will now take its place. More Info.

The new site may have less content, but the core will now remain. And it will now play nicely with phones! Keep an eye on the DelphiDabbler Blog for news.

» Help

Find the position of the text cursor in a memo control

   

To determine the position of the cursor in a memo you should use messages, like in the example below.

var
  Row, Col: Integer; 
begin
  Row := SendMessage(Memo1.Handle, EM_LINEFROMCHAR, Memo1.SelStart, 0); 
  Col := Memo1.SelStart - SendMessage(Memo1.Handle, EM_LINEINDEX, Row, 0);
  Label1.caption := 'Row= ' + IntToStr(Row+1) + ' Col= ' + IntToStr(Col+1);
end;
The MemoCursorPos routine from the Code Snippets Database uses the code presented in this tip.
Author: Shlomo Abuisak
Contributor: Shlomo Abuisak
Added: 2009-11-05
Last updated: 2013-10-12

« Return to contents »