troubleshooting Question

How to retrieve indexes of selected lines in RichEdit

Avatar of bernani
bernaniFlag for Belgium asked on
Editors IDEs
4 Comments1 Solution317 ViewsLast Modified:
Hi,

In a RichEdit, I've got this kind of lines (all lines can be numbered from 1 up to 9999).

1 jaiusjfdhrtfhjgjgjgj
2 mperthgbnhjkjljjjk
3 sdklfdmsqfmlkyrp
4 iopipqfdskkfsqfou      --> Selection begins here
5 adfkljsqfdsqlksdjf
6 dfqsizualjlfksqjflkl      --> Selection ends here
7 fdsquizaorzkljlsds
8 qfkljlzaiotuerzlktjkl
9 fdsqoitykelmkqkm
10 arozepipeirlmdq
11 qskjfldçtzekljdqs
12 ogsogdfkjllkjgds

What's the best way to retrieve which are selected lines to be able to perform some action on them. How do I retrieve the first and last line indexes of selected part of text ?

Sth like retrieving TheFirstSelectedLine and TheLastSelectedLine to initialize a for..loop similar to:

var
TheFirstSelectedLine, TheLastSelectedLine : Integer

{...}

if RichEdit.SelText <> '' then
begin
TheFirstSelectedLine:= ...;
TheLastSelectedLine:= ...;
  for i:= TheFirstSelectedLine to TheLastSelectedLine do
  begin
  {...}
  end;
end;

In the above example, I wanna remove the numbering part in order the text becomes

1 jaiusjfdhrtfhjgjgjgj
2 mperthgbnhjkjljjjk
3 sdklfdmsqfmlkyrp
iopipqfoooooooo
adfkljsoooooooo
dfqoooooooosqjfl
7 fdsquizaorzkljlsds
8 qfkljlzaiotuerzlktjkl
9 fdsqoitykelmkqkm
10 arozepipeirlmdq
11 qskjfldçtzekljdqs
12 ogsogdfkjllkjgds

and write a report at the end of the doc: Lines 4-6 were changed.

Thanks for your help.

Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 4 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros