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

How to get the selected text from a Memo control

By , About.com Guide

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

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 get the selected text from a Memo control

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

All rights reserved.