Memo Clicks

[Home]   [Puzzles & Projects]    [Delphi Techniques]   [Math topics]   [Library]   [Utilities]




Search WWW


As of October, 2016, Embarcadero is offering a free release of Delphi (Delphi 10.1 Berlin Starter Edition ).     There are a few restrictions, but it is a welcome step toward making more programmers aware of the joys of Delphi.  They do say "Offer may be withdrawn at any time", so don't delay if you want to check it out.  Please use the feedback link to let me know if the link stops working.


Support DFF - Shop

 If you shop at Amazon anyway,  consider using this link. 


We receive a few cents from each purchase.  Thanks


Support DFF - Donate

 If you benefit from the website,  in terms of knowledge, entertainment value, or something otherwise useful, consider making a donation via PayPal  to help defray the costs.  (No PayPal account necessary to donate via credit card.)  Transaction is secure.

Mensa Daily Puzzlers

For over 15 years Mensa Page-A-Day calendars have provided several puzzles a year for my programming pleasure.  Coding "solvers" is most fun, but many programs also allow user solving, convenient for "fill in the blanks" type.  Below are Amazon  links to the two most recent years.

Mensa 365 Puzzlers  Calendar 2017

Mensa 365 Puzzlers Calendar 2018

(Hint: If you can wait, current year calendars are usually on sale in January.)


Feedback:  Send an e-mail with your comments about this program (or anything else).

Search only




Problem Description

Here's a simple little program which illustrates the Delphi techniques for recognizing user clicks on a TMemo and determining the line number and the  position within the line where the click occurred.

Background & Techniques

I have used the techniques previously but always had difficulty finding exactly where and how to do it. The solution is two functions added to our DFFUtils unit.  Both depend on the TMemo OnClick event exit to respond to a click with the text based location in terms of the Lines property.  

Function LineNumberClicked(Memo:TMemo):integer; returns the line number clicked relative to 0 (the first line has line number 0). For the forgetful (me), alternative names defined for this function are: ClickedMemoLine, MemoLineClicked, and MemoClickedLine.  A standard Windows message, EM_LineFromChar, is sent to retrieve the line number clicked.

Function LinePositionClicked(Memo:TMemo):integer; returns the clicked position within the line relative to 1 (the first character in the line is position number 1); Again, for the forgetful,  alternative names defined for this function are: ClickedMemoPosition and MemoPositionClicked.  Position within the line is calculated by subtractg the character index of the start of the line (from posting an EM_LineIndex message) from the TMemo SelStart property value.

 To test the routines, click anywhere on the description memo text and the program will report the line and position clicked.

Running/Exploring the Program 

bulletDownload  executable
bulletDownload source 

Suggestions for Further Explorations



Original:  August 18, 2012

Modified:  May 15, 2018

  [Feedback]   [Newsletters (subscribe/view)] [About me]
Copyright 2000-2018, Gary Darby    All rights reserved.