
Search

Support DFF
If you shop at Amazon anyway, consider using this
link. We receive a few cents from each purchase. Thanks.
Support DFF
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.

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

|
| |
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
Suggestions for Further Explorations
 |
??? |
| |
|
| Original: August 18, 2012 |
Modified:
August 19, 2012
|
|