DelphiFAQ Home Search:

Access the current row/column of a TMemo

 

comments2 comments. Current rating: 4 stars (1 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);
begin
  Row := SendMessage(M.Handle, EM_LINEFROMCHAR, M.SelStart, 0);
  Col := M.SelStart-SendMessage(M.Handle, EM_LINEINDEX, Row, 0);
end;

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

Content-type: text/html

Comments:

2008-05-15, 19:27:21
gutergues@gmail.com  
rating
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

 

 

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: