Page 1 of 1
Goto same line on next page
Posted: Thu Oct 03, 2013 10:17 am
by JDommi
I'm trying to add text to the same line on multiple pages.
At the moment I'm realizing this by searching the first text occurence on each page as it always is the same word, count the difference between this item and the current item and repeat these steps for every page. But sometimes the item count differs from one page to another.
The better way would be to get the current line number of the first page and then scroll to the same line on the next page.
How can I perform this?
JDommi
Posted: Thu Oct 03, 2013 4:11 pm
by Sergey Tkachenko
But adding text in the middle of document may affect pagination?
Posted: Thu Oct 03, 2013 5:19 pm
by JDommi
Okay, in general I have to agree. But in my case it does not.
I have a numbered list with a name and have to add "only" a short phrase that will not affect the pagination.
Posted: Fri Oct 04, 2013 8:14 pm
by Sergey Tkachenko
The better way would be to get the current line number of the first page and then scroll to the same line on the next page.
I assume by "line number" you assume "paragraph number", because line number depends on word wrapping and can be different on the screen and on paper (in TRichViewEdit+TRVPrint; in ScaleRichView, lines are the same on the screen and on paper).
The requested functions are below.
This function returns the current number of paragraph (more exactly, of paragraph section; not only paragraph breaks (added by Enter key) but also line breaks added by Shift+Enter are taken into account).
For the first paragraph, it returns 0, for the second - 1, and so on.
Code: Select all
function GetCurrentParagraphIndex(rve: TCustomRichViewEdit): Integer;
var i: Integer;
begin
Result := 0;
for i := rve.CurItemNo downto 1 do
if rve.IsFromNewLine(i) then
inc(Result);
end;
The next function moves the caret down by the specified number of paragraphs (more exactly, paragraph sections). ParaCount=0 is ignored. ParaCount=1 moves to the beginning of the next paragraph; ParaCount=2 moves to the beginning of next after next paragraph, and so on:
Code: Select all
function MoveDown(rve: TCustomRichViewEdit; ParaCount: Integer): Boolean;
var
i: Integer;
begin
Result := False;
if ParaCount<=0 then
exit;
for i := rve.CurItemNo+1 to rve.ItemCount-1 do
if rve.IsFromNewLine(i) then begin
dec(ParaCount);
if ParaCount=0 then begin
rve.SetSelectionBounds(i, rve.GetOffsBeforeItem(i), i, rve.GetOffsBeforeItem(i));
Result := True;
exit;
end;
end;
end;
Place the caret on the desired line of the first page. Store the result of GetCurrentParagraphIndex.
Move the caret to the first line of the second page. Then call MoveDown, using the stored value as a parameter.
Posted: Fri Oct 04, 2013 9:31 pm
by JDommi
Simply great
Looks as it will do the thing. Tomorrow I will test it in my source.
Posted: Sat Oct 05, 2013 10:01 am
by JDommi
I just have updated my source with these two functions and they work like a charm
Big thanks to you