• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 243
  • Last Modified:

inserting line numbers into a trichedit

hi,

i ran into problem, that sounds trivial but i can't figure it out.

i have a richedit with a file loaded, or text in it. i need to insert in the 1st position of each line the line number.
now richedit doesn;t have an append procedure as a memo.

any way to do this?

thanks in advance.
0
urif
Asked:
urif
  • 4
  • 2
1 Solution
 
zebadaCommented:
Maybe I'm missing something but couldn't you just do this?

  for l:=0 to richEdit1.Lines.Count do
    richEdit1.Lines[l] := Format('%5d: ',[l+1])+richEdit1.Lines[l];
0
 
urifAuthor Commented:
maybe... let try, but i was searching for something similar to tmemo.insert(string)
where the string is inserted where the cursor is.

ok, maybe let me refresh the question, i need to insert the line numbers using a way similar to tmemo.insert

thanks! i really apprecite it
0
 
craig_capelCommented:
Var
  N: Integer;
begin
 For N:=0 to Richedit1.Lines.Count-1 Do
   Richedit1.Lines[N]:=IntToStr(N)+' '+Richedit1.Lines[N];
End;

Basically the same thing as above...
0
Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

 
zebadaCommented:
Ok, I give up, what is tmemo.insert(string).
Do you mean to use SetCaretPos to set the cursor position and PasteFromClipboard to insert text at the caret position?

0
 
urifAuthor Commented:
the problem with the 1st approach is that it goes nuts when the wordwrap is on, ans when you take the wordwrap, set it to off, then the line numbers get all messed.

the only way i found to solve this is either formatting the string differently, like %.5d or %-5d, the 1st will give me leading zeros of course and the second will align the number to the left.

the second approach causes the same problem.

that's why i thought on something similar to tmemo.insert

thanks
0
 
urifAuthor Commented:
what a memo.insert does is to inser a string where the cursor is positioned.

richedit does have an insert, but you need to get the current position of the caret and then call the fuction.

what i saw is to go line by line, and insert the number in the beginning of the line.

thanks
0
 
urifAuthor Commented:
i guess there is no way to arbitrarily insert text in richedit components. so the points goes to the 1st approach


thanks for the effort
0

Featured Post

2018 Annual Membership Survey

Here at Experts Exchange, we strive to give members the best experience. Help us improve the site by taking this survey today! (Bonus: Be entered to win a great tech prize for participating!)

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now