?
Solved

inserting line numbers into a trichedit

Posted on 2003-02-27
7
Medium Priority
?
242 Views
Last Modified: 2010-04-04
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
Comment
Question by:urif
[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
  • 4
  • 2
7 Comments
 
LVL 6

Accepted Solution

by:
zebada earned 200 total points
ID: 8031997
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
 

Author Comment

by:urif
ID: 8032021
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
 
LVL 2

Expert Comment

by:craig_capel
ID: 8032091
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
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 6

Expert Comment

by:zebada
ID: 8032136
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
 

Author Comment

by:urif
ID: 8032139
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
 

Author Comment

by:urif
ID: 8032159
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
 

Author Comment

by:urif
ID: 8032252
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses
Course of the Month14 days, 16 hours left to enroll

770 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