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!

How can I jump to a line in a TMemo or TRichEdit 1

Status
Not open for further replies.

LucieLastic

Programmer
May 9, 2001
1,694
GB
hi All

I read a text file and load it in to a control for viewing. I need to jump to the line which is of interest to the user but don't know how to do it.

TMemo doesn't seem to have anything. I'm currently trying with a TRichEdit and I set the position using SelStart and SelLength but although the cursor is on the correct line, it doesn't actually jump down to the line so the user can see the cursor.

Any ideas? I'm basically wanting to write a file editor type thing so the user is set to the correct position in the file, they add their appropriate lines and it saves. But I'm stuck.

Any help appreciated,
Lou

www.radbmx.co.uk
 
I found the following from:
Code:
procedure TForm1.Button1Click(Sender: TObject);
var
  LineNr: integer;
begin
  LineNr := StrToInt(Edit1.Text);
  RichEdit1.SelStart := RichEdit1.Perform(EM_LINEINDEX, LineNr, 0);
  Memo1.SelLength := 0;
end;

and the following from:
Code:
procedure TForm1.Button1Click(Sender: TObject);
var
  i: integer;
begin
  for i := 1 to 5 do 
    Memo1.Lines.Add('Lines added: ' + IntToStr(i));
  SendMessage(Memo1.Handle, EM_SCROLLCARET, 0, 0); 
end;

Perhaps try calling the EM_SCROLLCARET message?
 
That's brilliant! Thanks DjangMan.

I got it using the EM_SCROLLCARET:

mmOutput.SelStart := FilePosition;
SendMessage(mmOutput.Handle, EM_SCROLLCARET, 0, 0);


Thanks again,
Lou

www.radbmx.co.uk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top