Hello!
How can I get the current line index in pascal script?
Current line index
Re: Current line index
Code: Select all
var
y: Integer;
begin
y := Document.CursorY;
ShowMessage(y);
end.
Alium tibi quaere fratrem; hic, quem tuum putas, meus est. Titus Flāvius Caesar Vespasiānus Augustus
Re: Current line index
Thanks!
And how I can delete the current line in pascal?
And how I can delete the current line in pascal?
Re: Current line index
First off, let me show you the answer in JavaScript, it's easier for me and shouldn't be hard for you to translate it to Pascal; just remember, JS surrounds strings with double quotes, while Pascal with single ones.
Here's a quick solution:
Variable y holds the index of line with cursor, maxY is the number of all lines in your document minus 1 (index of the last line, that is.) The code loops through all remaining lines (after y), copying them up, then deletes the doubled last line. You end up with blank line at the end of your document, which can be then easily removed during save.
If you don't have blank lines in your document, you can use
You could also use
but JoinLines doesn't work with blank lines, which imho is a bug and I'm going to report it.
Hope that helps!
Here's a quick solution:
Code: Select all
var y = Document.CursorY;
Document.CursorDocEnd(false);
var maxY = Document.CursorY;
for (var i = y; i < maxY; i++) {
Document.Lines[i] = Document.Lines[i + 1];
}
Document.Lines[maxY] = "";
If you don't have blank lines in your document, you can use
Code: Select all
var y = Document.CursorY;
Document.Lines[y] = "";
Document.DeleteBlankLines();
Code: Select all
var y = Document.CursorY;
Document.Lines[y] = "";
Document.JoinLines();
Hope that helps!
Alium tibi quaere fratrem; hic, quem tuum putas, meus est. Titus Flāvius Caesar Vespasiānus Augustus
Re: Current line index
Thanks!
But I found another solution.
But I found another solution.

Code: Select all
//Pascal
var
y: integer;
list: TStringList;
begin
Document.BeginUpdate();
Document.Wordwrap:= False;
y:= Document.CursorY; //Current line
list:= TStringList.Create;
list.Text:= Document.Text;
list.Delete(y);
Document.Text:= list.Text; //after paste cursor is in the end of the document
Document.CursorY:=y; //set cursor in start position
list.free;
Document.Wordwrap:= True;
Document.EndUpdate();
end;
Re: Current line index
This is cool! Thanks for sharing 

Alium tibi quaere fratrem; hic, quem tuum putas, meus est. Titus Flāvius Caesar Vespasiānus Augustus
- Rickard Johansson
- Site Admin
- Posts: 6783
- Joined: 19 Jul 2006 14:29
Re: Current line index
A simpler way to delete the current line would be add:
Just saying 
Code: Select all
...
Document.SelectCurrentLine;
Document.SelText := '';
...

Re: Current line index
This doesn't delete line for me, just makes it empty -- but the newline is still there (at least in JS.)
Alium tibi quaere fratrem; hic, quem tuum putas, meus est. Titus Flāvius Caesar Vespasiānus Augustus
Re: Current line index
But in this case we delete only content of the line. And I need to delete full line with move up. In other words I need to delete the char #13 in the end of line.Rickard Johansson wrote:A simpler way to delete the current line would be add:Just sayingCode: Select all
... Document.SelectCurrentLine; Document.SelText := ''; ...

- Rickard Johansson
- Site Admin
- Posts: 6783
- Joined: 19 Jul 2006 14:29
Re: Current line index
Ah, well maybe this will work then

Code: Select all
...
y := Document.CursorY;
if (y < Document.LineCount - 1) then
Document.SetSelection(0, y, 0 , y+1)
else
Document.SetSelection(Length(Document.Lines[y-1]), y-1, Length(Document.Lines[y]), y);
Document.SelText := '';
...