C++ Builder Tutorials

C++Builder Tips: Line number in a TMemo

To determine which line number the cursor of a Memo component is in, you can use the Windows API function SendMessage (API = Application Programmer Interface).

In the example below, the integer variable LNr receives the line number that the cursor of Memo1 is in:

void __fastcall TForm2::Button1Click(TObject *Sender)
{
  int LNr;
  LNr = SendMessage(Memo1->Handle, EM_LINEFROMCHAR, Memo1->SelStart, 0);
  Label1->Caption = IntToStr(LNr);
}
See also:

  Components: TMemo