Author: Jonas Bilinkevicius
I am currently trapping the OnMouseMove event, however have run into significant
problems converting the mouse coordinates into a line and character offset in a
rich edit.
Answer:
1 2 procedure TForm1.RichEdit1MouseMove(Sender: TObject; Shift: TShiftState; X, Y:
3 Integer);
4 var5 Point: TPoint;
6 Value: LongInt;
7 LineNumber: Integer;
8 LinePos: Integer;
9 Line: string;
10 begin11 {Get absolute position of character beneath mouse}12 Point.x := X;
13 Point.y := Y;
14 Value := RichEdit1.Perform(EM_CHARFROMPOS, 0, LParam(@Point));
15 if Value >= 0 then16 begin17 {Get line number}18 LineNumber := RichEdit1.Perform(EM_LINEFROMCHAR, Value, 0);
19 {Get line position}20 LinePos := Value - RichEdit1.Perform(EM_LINEINDEX, LineNumber, 0);
21 {Get line}22 Line := RichEdit1.Lines[LineNumber];
23 Label1.Caption := Format('Line: %d Column: %d: %s', [LineNumber, LinePos,
24 Line]);
25 end26 else27 begin28 Label1.Caption := EmptyStr;
29 end;
30 end;
This only works for RichEdits.