Solved

Line Number

Posted on 1998-12-11
1
169 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
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

821 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