Page 1 of 1

How to map Item# to location info

Posted: Wed Apr 02, 2008 2:19 am
by toolwiz
If I've got a document loaded into an SRV and a list of items in the document with ItemNo values, how can I get the Page#, Line#, and Col# of each ItemNo? (I just need the starting Page# and Line#.)

Posted: Wed Apr 02, 2008 1:04 pm
by proxy3d
Result - PageNo

Code: Select all

function getInfo(ItemNo, OffsetItem : Integer; var Line, Column : Integer) : Integer;
var 
     PageNo : Integer;
     IndexB, IndexE, Offs : Integer; // DrawItemNo
begin
  SRV.RichViewEdit.RVData.Item2DrawItem(ItemNo, OffsetItem, IndexE, Offs);
  PageNo := SRV.getRVPageNoEx(DrawItemNo);
  indexB := SRV.getPageStartDrawItemNo(PageNo);
  Result := PageNo;

  if (indexB >= 0) then
    begin
      Line := 0;
      // Line
      while (IndexB <= IndexE) do
        begin
          if SRV.RichViewEdit.RVData.DrawItems.Items[indexB].FromNewLine then
            Line := Line + 1;
          indexB := indexB + 1;
        end;
      // Col
      if (SRV.getPageStartDrawItemNo(PageNo) <= IndexE) then
        indexB := indexB - 1;
      IndexE := indexB;
      indexB := SRV.getPageStartDrawItemNo(PageNo);
      Column := Offs;
      while (not SRV.RichViewEdit.RVData.DrawItems.Items[indexE].FromNewLine) do
        begin
          IndexE := IndexE - 1;
          if (IndexE >= IndexB) then
            Column := Column + SRV.RichViewEdit.RVData.DrawItems.Items[indexE].Length
          else
            break;
        end;
    end
  else
    begin
      Line := 1;
      Column := 1;
    end;
end;
See also:
function getPageStartDrawItemNo(PageNo : Integer) : Integer;