delphidelphi-2010tmemo

Delphi memo why cursor going to the Left always


In my VCL project, I have a TMemo with the following text (| is the caret):

|                   |  
|Hello world |      |  
|                   |  
|test               |  
|                   |  
|                   |    

When I press the Down button, the caret moves here:

|                   |  
|Hello world        |  
||                  |  
|test               |
|                   |  
|                   |  

What I need is for it to move here instead:

|                   |  
|Hello world        |  
|               |   |   
|test               |  
|                   |  
|                   | 

Solution

  • I think you would find it instructive to devise your own solution for this. The default behaviour for a TMemo responding to the Down key depends on how many characters there are on the next line. If there are at least as many on the next line as there are on the current line, the caret will stay in the same column number.

    So a simple solution might be

    With a bit of googling you can easily find Delphi code to detect the current line and column number of the caret in a TMemo.