Author: Tomas Rutkauskas
I want to write an Edit component, but I want the cursor to stay on the right when
the user types in new characters.
Answer:
1 procedure TForm1.Edit1Change(Sender: TObject);
2 begin3 if IsChanging then4 exit; {Avoid recursion}5 IsChanging := true;
6 try7 {Remove the first character}8 Edit1.Text := copy(Edit1.Text, 2, length(Edit1.Text) - 1);
9 {And move the cursor to the end of the text}10 Edit1.SelStart := length(Edit1.Text);
11 finally12 IsChanging := false;
13 end;
14 end;
At design time (or in Create), put several spaces as Edit1.Text. They will be replaced one by one with characters typed by the user. IsChanging is a private variable of type boolean.