1. Home
  2. Computing & Technology
  3. Delphi Programming

How to click-and-select a line in TMemo

By , About.com Guide

Here's how to select a row (line) of text in a TMemo control by clicking on it:

Note:Drop a TMemo (Memo1) on a form and call the "SelectMemoLine" procedure from Memo's OnClick event:
~~~~~~~~~~~~~~~~~~~~~~~~~
procedure SelectMemoLine(Memo : TCustomMemo) ;
var
   Line : integer;
begin
   with Memo do
   begin
     Line := Perform(EM_LINEFROMCHAR, SelStart, 0) ;
     SelStart := Perform(EM_LINEINDEX, Line, 0) ;
     SelLength := Length(Lines[Line]) ;
   end;
end;

//Usage:
procedure TForm1.Memo1Click(Sender: TObject) ;
begin
   SelectMemoLine(Memo1) ;
end;
~~~~~~~~~~~~~~~~~~~~~~~~~

If you are looking for more TMemo related tips: TMemo to the Max

Delphi tips navigator:
» How to focus a specific cell (by field name) in a DBGrid Delphi component
« How to start your favorite application directly from the Delphi IDE

More Delphi Programming Quick Tips
Explore Delphi Programming
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Using VCL Components
  5. TMemo, TRichEdit
  6. How to click-and-select a line in TMemo Delphi component

©2009 About.com, a part of The New York Times Company.

All rights reserved.