5

i searched google but can't seem to find a working solution.

the situation is unique. i need to "add" lines with a comment at various times. whenever i press the F9 key, a line number will dispaly followed by a colon ":" char and then i enter some comments at the line number and cursor position.

the running output should look like this:

001: startup time
002: watched tv
003: |

where "|" is the last cursor position at runtime, waiting for me to enter some text.

but instead, when i run the program and press the F9 key, i get this:

001: 
002: 
003: 
|

where "|" is the last cursor position at runtime, waiting for me to enter some text.

how can remove that (last) blank line in a memo?

johnm2
  • 143
  • 3
  • 8

1 Answers1

17

Add() inserts a line break after the inserted text. If you do not want the line break, then use the SelText property instead, eg;

Memo1.SelStart := Memo1.GetTextLen;
Memo1.SelLength := 0;
Memo1.SelText := '003: ';
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • 1
    this worked. i added the code to the FormActivate event so that the error is non-existant. thank you. – johnm2 Jan 07 '13 at 05:17
  • 1
    Instead of at FormActivate event, you may put the Remy Lebeau's code at Memo1KeyDown event. For example, Memo1.Lines.Add('003') inside Memo1KeyDown can be replaced by the three lines shown by Remy Lebeau. – sevenOfNine Nov 29 '13 at 00:31