DelphiFAQ Home Search:

Access the current row/column of a TMemo


comments3 comments. Current rating: 3 stars (2 votes). Leave comments and/ or rate it.

The following code reads and writes the cursor's position as row and column; counting starts at 0.

(To scroll to the cursor position, also read this tip:
Have a TMemo/ TRichEdit scroll to the cursor position.)

procedure GetMemoRowCol (M : TMemo; var Row, Col : LongInt);
  Row := SendMessage(M.Handle, EM_LINEFROMCHAR, M.SelStart, 0);
  Col := M.SelStart-SendMessage(M.Handle, EM_LINEINDEX, Row, 0);

procedure SetMemoRowCol(M : TMemo; Row, Col : Integer);
  M.SelStart := SendMessage(M.Handle, EM_LINEINDEX, Row, 0)
                + Col;

Content-type: text/html


2008-05-15, 19:27:21  
Esta dica me ajudou muito quando eu precisava posicionar o cursor em uma determinada linha...
Muito boa.
2008-10-12, 19:37:44   (updated: 2008-10-12, 19:38:19)
anonymous from New Zealand  
just what i was looking for. many thanks
2020-06-03, 16:23:40
Emilio from United Kingdom  
albuterol price inhaler



NEW: Optional: Register   Login
Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option, or post under a registered account.

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity.
The owner of this web site reserves the right to delete such material.

photo Add a picture: