Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

move cursor in TRichEdit

Posted on 1999-07-22
Medium Priority
1,007 Views
How can we change the cursor position to another line by
the Delphi code?
0
Question by:mathematics
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

Author Comment

ID: 1390366
and how to move to the last line?
0

Accepted Solution

Vovbager earned 200 total points
ID: 1390367
SendMessage(RichEdit1.Handle,EM_SETSEL,20,20);

this example sets cursor in RichEdit at 20th char position.

0

LVL 7

Expert Comment

ID: 1390368
You can use these two procedures...

procedure TForm1.MoveToLine( ARichEdit : TRichEdit; LineNumber : Word);
var
Loopvariable : Word;
RunningLength : Word;
begin
RunningLength := 0;
for loopVariable := 0 to LineNumber-1 do
begin
RunningLength := RunningLength + Length(ARichEdit.Lines[LoopVariable]);
end;
SendMessage(ARichEdit.Handle, EM_SETSEL, RunningLength+1,RunningLength+1);
ARichEdit.Setfocus;
end;

procedure TForm1.MoveToLastLine(ARichEdit : TRichEdit);

var
Mylength : word;
LastLineLength : word;
SetPosition : word;
begin
MyLength := Length(ARichEdit.Lines.Text)-2;
LastLineLength := Length(ARichEdit.Lines[ARichEdit.Lines.Count-1]);
SetPosition := MyLength - LastLineLength;
SendMessage(ARichEdit.Handle, EM_SETSEL, SetPosition,SetPosition);
ARichEdit.Setfocus;
end;

Rob
0

LVL 27

Expert Comment

ID: 1390369
hi mathematics,

my version

procedure TForm1.Button1Click(Sender: TObject);
var
curLine,
firstCharNextLine : Integer;
begin
CurLine := Richedit1.Perform(EM_LINEFROMCHAR,Richedit1.Selstart,0);
firstCharNextLine := Richedit1.Perform(EM_LINEINDEX,CurLine+1,0);
If firstCharNextLine = -1 then
Showmessage('No Next Line Available')
else
Richedit1.SelStart := firstCharNextLine;
Richedit1.SetFocus;
end;

for the lastline use
firstCharNextLine := Richedit1.Perform(EM_LINEINDEX,Richedit1.lines.count-1,0);

meikl
0

LVL 7

Expert Comment

ID: 1390370
Meikl thats a much nicer solution :-)
0

Author Comment

ID: 1390371
thanks!
0

Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month5 days, 9 hours left to enroll