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
Goto same line on next page
-
- Site Admin
- Posts: 17569
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
-
- Site Admin
- Posts: 17569
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
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 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.
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;
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;
Move the caret to the first line of the second page. Then call MoveDown, using the stored value as a parameter.