Hi Sergey,
Is there a way to get the paragraph index? By that I mean, if there are 3 paragraphs in the rve doc, how do I get their index (1, 2, or 3?). Something like rve.GetItemParaIndex or something like that? Note that I'm not talking about paragraph number formatting, or the style index, but the underlying index of a given paragraph. Like line numbers only just the paragraphs.
Thanks Sergey
Stan
Paragraph Index
-
- Site Admin
- Posts: 17554
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Re: Paragraph Index
Indexes of paragraphs are not stored. So the only way is calculating:
This function returns the index of the item's paragraph (1-based).
Tables and horizontal lines are counted as one paragraph.
Call for an item in the root document:
Call for an item in a table cell:
(in this call, paragraphs are counted from the beginning of this cell).
Code: Select all
function GetItemParaIndex(RVData: TCustomRVData; ItemNo: Integer): Integer;
var
i: Integer;
begin
Result := 0;
for i := ItemNo downto 0 do
if RVData.IsParaStart(i) then
inc(Result);
end;
Tables and horizontal lines are counted as one paragraph.
Call for an item in the root document:
Code: Select all
ParaIndex := GetItemParaIndex(RichView1.RVData, ItemNo)
Code: Select all
ParaIndex := GetItemParaIndex(Table.Cells[r,c].GetRVData, ItemNo)
Re: Paragraph Index
Hi Sergey,
OK, I kind of remember this now. I put that in and it works for what I'm doing.
From what I can see, getting the line number works in a similar way, yes? Calculated, not stored? So, if my code is this:
The time it takes to do either one should be about the same?
Thanks again Sergey.
Stan
OK, I kind of remember this now. I put that in and it works for what I'm doing.
From what I can see, getting the line number works in a similar way, yes? Calculated, not stored? So, if my code is this:
Code: Select all
if NumberWrapLines1.Checked then
LineNumber := memo.GetLineNo(DItem.ItemNo,DItem.Offs)
else
LineNumber := GetItemParaIndex(memo.RVData,DItem.ItemNo);
Thanks again Sergey.
Stan
-
- Site Admin
- Posts: 17554
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Re: Paragraph Index
Yes, this code is correct. Yes, indexes of lines are not stored, they are calculated as well.
Calculation of both lines and paragraphs is very fast, so it may be a problem only if you call it many times repeatedly.
Calculation of both lines and paragraphs is very fast, so it may be a problem only if you call it many times repeatedly.
Re: Paragraph Index
I'm using them for my rve line numbers. My test 100kb files with 3k to 4k lines work fine, even when scrolling which is when they get called a lot. It's all used in paint calls so everything seems fast enough. It's very unlikely I'll be using files anywhere that big normally but I like to test with them.Sergey Tkachenko wrote: ↑Sat Dec 18, 2021 6:28 pm Yes, this code is correct. Yes, indexes of lines are not stored, they are calculated as well.
Calculation of both lines and paragraphs is very fast, so it may be a problem only if you call it many times repeatedly.
So far the hardest thing (for me) was to figure out how to number the wrapped lines. I have to use draw items for that and I'm still trying to figure those out. But it's all working pretty well at this point.
Stan