views:

603

answers:

2

Hi

I am adding lines to a TRichEdit how do I keep focus on the line that has just been added?

For Idx := 1 to 1000 do
   RichEdit.Lines.add(IntToStr(Idx));

EDIT

I just what the bottom line of the richedit to show what was just added and all the other lines to scroll up

+3  A: 

You can try this

option 1) set the cursor when the loop finish

For Idx := 1 to 1000 do
   RichEdit.Lines.add(IntToStr(Idx));

RichEdit.SetFocus;
RichEdit.SelStart := RichEdit.Perform(EM_LINEINDEX, RichEdit.Lines.Count-1, 0) ;

option 2) set the cursor while the loop is executing

For Idx := 1 to 1000 do
Begin
RichEdit.Lines.add(IntToStr(Idx));
RichEdit.SetFocus;
End;

RichEdit.SelStart := RichEdit.Perform(EM_LINEINDEX, RichEdit.Lines.Count-1, 0) ;

Bye.

RRUZ
+4  A: 

This should work, if you just want to scroll to the end of the richedit:

For Idx := 1 to 1000 do
begin
  RichEdit.Lines.add(IntToStr(Idx));
  RichEdit.SelStart := RichEdit.GetTextLen;
  SendMessage(RichEdit.handle, EM_SCROLLCARET,0,0);
end;

If this is not what you wanted, please see my comment above and clarify your question.

Argalatyr
Thanks - this works nicely :)
Charles Faiga