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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I set the position in TMemo? 1

Status
Not open for further replies.

doctorjellybean

Programmer
May 5, 2003
145
The TMemo component loads the contents of a text file. After loading, I need to set the position to the beginning of the first line (row).

Then I want to insert some info at that position, and move down to the beginning of the next line (row). I'm basically trying to insert timestamps into the beginning of each line (row). The timestamps are obtained from another procedure.

Thank you.
 
I haven't tried it, but I would guess that
Code:
Memo1.SelStart := line;

where line is an integer 0 to count-1 may do it?


Steve (Delphi 2007 & XP)
 
Thank you.

It sets the position of the cursor on the line itself, where
Memo1.SelStart := 0;
is the first character on the first line. Now I need to put the cursor at the beginning of the 2nd line, and this is what I would like to know.
 
ok, try this one:
Code:
procedure TMainForm.Button6Click(Sender: TObject);
begin
  with Memo1 do
  begin
    // Move to 3rd line, Character 3:
    SelStart := Perform(EM_LINEINDEX, 2, 0) + 3;
    Memo1.SelLength := 0;
    Perform(EM_SCROLLCARET, 0, 0);
    Memo1.SetFocus;
  end;
end;

The 2 is the 3rd line (0,1,2, etc).
Change the +3 to +0 to put the cursor at the begginning of the line.
You probably don't need the SetFocus, I used that in my test button to see the cursor flashing at the right place.



Steve (Delphi 2007 & XP)
 
You're welcome.
Usually it's me asking, so good to be the answerer for once..


Steve (Delphi 2007 & XP)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top