22 Votes

Lazarus: Get current Line Index from Memo

Question by Guest | Last update on 2022-05-02 | Created on 2014-01-22

I would like to retrieve the index of the line in which the user is currently writing from a TMemo.

Unfortunately, my previous searches only brought a solutions for Delphi to light with which it should be possible to determine the current line and column within a Memo like this:

Line   := Memo1.Perform(EM_LINEFROMCHAR, Memo1.SelStart, 0) ;
Column := Memo1.SelStart - Memo1.Perform(EM_LINEINDEX, Line, 0) ;

In Lazarus this is not working (Error Message: "Identifier not found EM_LINEFROMCHAR"). Does someone have a solution?

ReplyPositiveNegativeDateVotes
7Best Answer7 Votes

It is much more easier.

Just try this:

Line   := Memo1.CaretPos.Y;
Column := Memo1.CaretPos.X;

CaretPos is the position of the cursor. It has a X and a Y variable in which the values you are searching for are stored.

As far as I know, "Perform" and "EM_LINEFROMCHAR" are typical for the Windows world and we cannot use them in the platform independent Lazarus.
Last update on 2022-05-02 | Created on 2014-01-22

ReplyPositive Negative
11 Vote

The answer given by the other guest is the best solution.

Additionally, if you did want to go with your original route, you need to specify "windows" in the uses section.
2014-07-04 at 19:48

ReplyPositive Negative
Reply

Related Topics

HTACCESS: Simplify URL

Tutorial | 0 Comments

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own article on askingbox.com. That’s how it’s done.