Solved

Line Number

Posted on 1998-12-11
1
171 Views
Last Modified: 2010-04-04
How can I get the Line Number of a Memo (TStrings) Object, where the Cursor is currently positioned ?
0
Comment
Question by:omsec
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 4

Accepted Solution

by:
jeurk earned 10 total points
ID: 1350537

The trick is to use the em_LineFromChar message.  Try this:

procedure TMyForm.BitBtn1Click(Sender: TObject);
var
  iLine : Integer ;
begin
   iLine := Memo1.Perform(em_LineFromChar, $FFFF, 0);
   { Note: First line is zero }
   messageDlg('Line Number: ' + IntToStr(iLine), mtInformation,
              [mbOK], 0 ) ;
end;

or

{The following two methods are used to get row/column coordinates.     }
{There are no messages that explicitly provide column information but the}
{EM_GETSEL message provides the position of the caret if a selection is  }
{not currently active. When text is selected the caret can be positioned at }
{the beginning or the end of the selection depending how it was selected.}
{Thus these methods may be slightly inaccurate while text is selected. }

function  TNotePad.GetColumn: SmallInt;
begin
  Result := (SelStart+SelLength) -        {Assume that caret is at end of Selection}
            Perform(EM_LINEINDEX, -1, 0); {Method version of SendMessage}
end;

function  TNotePad.GetRow: SmallInt;
begin
  Result := LongRec(Perform(EM_LINEFROMCHAR, -1, 0)).Lo; {Get Low word}
end;

Regards

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question