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

How to get the selected text from a Memo control

By Zarko Gajic, About.com

If you need to know what portion of the text a user selected in a TMemo (or TEdit) component, right after the selection was made, you can use the next code in the OnMouseUp event handler for a TMemo (named Memo1 in the code below) control:

~~~~~~~~~~~~~~~~~~~~~~~~~
procedure TForm1.Memo1MouseUp(
   Sender: TObject; Button: TMouseButton;
   Shift: TShiftState; X, Y: Integer) ;
var
   selection : string;
begin
   selection := Memo1.SelText;
   ShowMessage('Text selected: ' + selection)
end;
~~~~~~~~~~~~~~~~~~~~~~~~~

Delphi tips navigator:
» How to move the mouse cursor to the focused control when the form is displayed
« How to add leading zeroes to a number

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

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

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Using VCL Components
  5. TMemo, TRichEdit
  6. How to get the selected text from a Memo control

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

All rights reserved.