success - (nearly...)
i think you'll agree we are pretty close. there is just a little bit of flicker. this flicker is the selstart jumping the cursor position around the text. we need to hide this. this "cursor" is also known as a caret. looking throught win32.hlp again we find the lovely, and appropriately named, hidecaret() function.
lets try this then: everytime we change the value of myre.selstart lets call hidecaret(myre.handle) immediately before.
i'll be kind - that doesn't work. i tried 2 x hidecaret(myre.handle), and it still didn't work. neither did three,four or 25x. so close - but yet - so far. i think its time for another delphi rule:
delphi rule #5 - if you bother to get your way through the atrocious index of the win32.hlp file to find what you are looking for - make sure you really read what you found properly!
the key was the last paragraph in the description of not hidecaret but showcaret (which i had also read as i thought we were going to need it, especially to reverse my 25x hidecaret()). you also need another delphi rule to understand it:
| the caret is a shared resource; there is only one caret in the system. a window should show a caret only when the window has the keyboard focus or is active. |
delphi rule #6 - everything (basically) is a window
you see the richedit is a windows control and is also.. in a weird sense.. a window. it has a handle, which is why hidecaret would accept it. so re-reading the last line again we get:
| the caret is a shared resource; there is only one caret in the system. a [richedit] should show a caret only when the [richedit] has the keyboard focus or is active. |
so - in the end - we're back to were we started - we have to disable the richedit to stop the final bit of flickering. this also (co-incidentially) means that em_hideselection is not needed anymore (if hideselection is set properly during design time). so in the end everyone gets 10/10 for marks!
ash version 0.9b
| procedure tform1.richedit1change(sender: tobject);
var
begin
end; |