We are adding an ASCII editor to our application, and we are using TRichEdit in Delphi XE7. We need to display the Row and Column in the status bar, but have not found any code that works with the Key down function. The code below is the current code we are using. The code below works perfect with the mouse down, but the key down is not consistent.
Row := SendMessage(asciieditor.Handle, EM_LINEFROMCHAR, asciieditor.SelStart, 0);
Col := asciieditor.SelStart - SendMessage(asciieditor.Handle, EM_LINEINDEX, Row, 0);
When you want to display the caret position in a Rich Edit control in the status bar, the usual way is to use the editor's
OnSelectionChangeevent:This is fired every time the caret pos or selection end point is moved, which is precisely what you need.
Attempting to keep the status bar updated using mouse and keyboard events is not a good idea. For instance, what if the user is editing or typing without using the mouse or keyboard? (For instance, programmatically or using speech recognition.)
And using
OnIdleis a waste of CPU cycles.