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
6
Medium Priority
?
1,007 Views
Last Modified: 2008-02-20
How can we change the cursor position to another line by
the Delphi code?
0
Comment
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
  • Learn & ask questions
6 Comments
 

Author Comment

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

Accepted Solution

by:
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

by:RBertora
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 27

Expert Comment

by:kretzschmar
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

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

Author Comment

by:mathematics
ID: 1390371
thanks!
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

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

664 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question