Paragraph Index

General TRichView support forum. Please post your questions here
Post Reply
standay
Posts: 274
Joined: Fri Jun 18, 2021 3:07 pm

Paragraph Index

Post by standay »

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
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Paragraph Index

Post by Sergey Tkachenko »

Indexes of paragraphs are not stored. So the only way is calculating:

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;
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:

Code: Select all

ParaIndex := GetItemParaIndex(RichView1.RVData, ItemNo)
Call for an item in a table cell:

Code: Select all

ParaIndex := GetItemParaIndex(Table.Cells[r,c].GetRVData, ItemNo)
(in this call, paragraphs are counted from the beginning of this cell).
standay
Posts: 274
Joined: Fri Jun 18, 2021 3:07 pm

Re: Paragraph Index

Post by standay »

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:

Code: Select all

      if NumberWrapLines1.Checked then
        LineNumber := memo.GetLineNo(DItem.ItemNo,DItem.Offs)
      else
        LineNumber := GetItemParaIndex(memo.RVData,DItem.ItemNo);
The time it takes to do either one should be about the same?

Thanks again Sergey.

Stan
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Paragraph Index

Post by Sergey Tkachenko »

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.
standay
Posts: 274
Joined: Fri Jun 18, 2021 3:07 pm

Re: Paragraph Index

Post by standay »

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.
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.

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
Image31.png
Image31.png (38.68 KiB) Viewed 6140 times
Post Reply