Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TMemo cursor position

Status
Not open for further replies.

lsalamon

Programmer
Jan 1, 2001
1
BR
How I set cursor position at the end of file and set focus to display it.
My application is to viewing log files and it increase at the end.

Thanks for any tips.

Salamon
 
One part of the problem is to find out where the cursor currently is. To do that, you must use Windows EM_LINEFROMCHAR message. For example:
Code:
int LNumber;
LNumber = SendMessage(Memo1->Handle, EM_LINEFROMCHAR, -1, 0);
ShowMessage(LineNumber);

I will have to research a lit more to find how to place the cursor in TMemo.

James P. Cottingham
 
Nevermind, I did:

MyTMemo->SelStart = MyTMemo->Text.Length();

As long as you aren't doing any text selection, this should work.
 
I know how to read where the cursor is:

Code:
int xPos, yPos;
xPos = Memo1->CaretPos.x;
yPos = Memo1->CaretPos.y;
and too, as long as you aren't doing any text selection, this should work.

but it seems that you want the cursor position to add more text to your file isn't? then I suggest to use an Append function.

--- LastCyborg ---
 
Hi Isalamon and sritzel,

I have been using the following code to scroll a memo, later adapted to a RichEdit, at their end. I wanted always to see the latest incoming Strings, which I add, when they arrive. After each add of a String to the Memo/RE->Text, I called this function.
(I found it more than a year ago and do not remember where, sorry)
It works quite fine, but it flickers a bit, maybe You go from here and find a way to get rid of the flicker?

// this routine keeps all outputs visible through
// scrolling of the specified TCustomMemo in the end
// (for using a RichEdit replace TMemo in the param list
// with TRichEdit)
Code:
void __fastcall TMyForm::ScrollCaret(TMemo *ScrollMemoSender)
{

//sets cursor to end of specified TCustomMemo:
ScrollMemoSender->SelStart=ScrollMemoSender->Text.Length(); 

//scrolls the specified TCustomMemo (one) last line:
SendMessage(ScrollMemoSender->Handle, EM_SCROLLCARET,0,0);  
}
I call this function like this in my code:

Code:
TMemo *CaretSender; //TRichEdit *CaretSender if You wish so  

CaretSender->Text = CaretSender->Text+MyNewString; 
// (maybe You have to add "\r\n", if needed)

ScrollCaret(CaretSender);

NOTE: I have tried
Code:
 "CaretSender->Text += MyNewString;"
and it does NOT WORK fine.

I hope this helps!
best regards,
Michael
;)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top