Lazarus
Home
Forum
Help
TinyPortal
Search
Login
Register
Lazarus
»
Forum
»
Using the Lazarus IDE
»
General
»
[SynEdit] How to get start and end line number of selection
Downloads
Daily Snapshots
FAQ
Wiki
Bugtracker
IRC channel
Developer Blog
Follow us on Twitter
Mailing List
Free pascal
Other languages
Useful Wiki Links
Project Roadmap
Getting the Source
Screenshots
About donations (wiki)
Bookstore
Lazarus, the complete guide
Search
Advanced search
« previous
next »
Print
Pages: [
1
]
Author
Topic: [SynEdit] How to get start and end line number of selection (Read 3595 times)
mrBrown
New member
Posts: 15
[SynEdit] How to get start and end line number of selection
«
on:
December 17, 2009, 08:58:43 am »
I'm using a SynEdit control to edit input scripts for an mechanical engineering application.
I want to give users the possibility to quickly (un)comment code lines by selecting a number of lines of code and clicking an (un)comment button.
I would like to do something like this:
for line := LineStart to LineEnd do SynEdit1.Lines[line] := '% ' + SynEdit1.Lines[line];
The problem is that I can not find the line numbers where the selection starts end ends.
SynEdit1.SelStart / End only gives me an index, which I don't know how to convert to a line number.
Anyone got an idea?
Logged
theo
Global Moderator
Hero Member
Posts: 1673
Re: [SynEdit] How to get start and end line number of selection
«
Reply #1 on:
December 17, 2009, 10:06:21 am »
CaretX, CaretY?
Logged
mrBrown
New member
Posts: 15
Re: [SynEdit] How to get start and end line number of selection
«
Reply #2 on:
December 17, 2009, 01:21:00 pm »
CaretX, CaretY give the position of the caret.
What I'm looking for are the start en end line of the selected text.
Logged
theo
Global Moderator
Hero Member
Posts: 1673
Re: [SynEdit] How to get start and end line number of selection
«
Reply #3 on:
December 17, 2009, 02:46:00 pm »
Quote from: mrBrown on December 17, 2009, 01:21:00 pm
CaretX, CaretY give the position of the caret.
Ah, sorry. I misunderstood the question.
But I don't know the answer to your question either.
What to do?
Look at the Synedit sources?
Hmm, lets search for SetSelStart.....ah interesting there is a
Blockbegin.X
Blockend.X
Hmmm.... ;-)
Logged
Martin_fr
Hero Member
Posts: 1218
Re: [SynEdit] How to get start and end line number of selection
«
Reply #4 on:
December 17, 2009, 04:03:05 pm »
Blockbegin.Y
Blockend.Y
are what you are looking for. Blockbegin is always the lower line number (or lower X, if the selection has one line only). They are sorted, if the selection was done "backward" (eg with shift cursor-up)
If Blockend.X=1, then you want to reduce BlockEnd.Y by 1. Because there are 0 chars selected in the last line. It simply means that the whole line above is selected (including carriage-return).
You may want to check SelectionMode too, if block or line mode selection need different treatment.
Logged
mrBrown
New member
Posts: 15
Re: [SynEdit] How to get start and end line number of selection
«
Reply #5 on:
December 18, 2009, 04:09:31 pm »
excellent!
somehow I didn't get from selection to "block" myself...
thanks for the help
Logged
Print
Pages: [
1
]
« previous
next »
Lazarus
»
Forum
»
Using the Lazarus IDE
»
General
»
[SynEdit] How to get start and end line number of selection
Recent
ListBox Filter
by
lainz
[
Today
at 05:00:07 am]
BGRAControls
by
lainz
[
Today
at 03:10:41 am]
FPCUp FPC/Lazarus SVN ins...
by
lainz
[
Today
at 03:09:38 am]
What is this Delphi Heade...
by
DirkS
[
Today
at 12:11:59 am]
Build of SQLite3 for WINC...
by
bambamns
[
Today
at 12:09:01 am]
Lazarus crashes after “Re...
by
and4977
[May 20, 2012, 11:26:31 pm]
Scrambled dragimage
by
Ocye
[May 20, 2012, 10:30:19 pm]
Transparency with Qt on D...
by
Ocye
[May 20, 2012, 08:14:43 pm]
DragImage adds as new win...
by
Ocye
[May 20, 2012, 08:05:24 pm]
TFrame size
by
iru
[May 20, 2012, 07:03:22 pm]