How to map Item# to location info

ScaleRichView support and discussion (TRichView add-on for WYSIWYG editing)
Post Reply
toolwiz
Posts: 150
Joined: Wed Nov 30, 2005 3:27 am

How to map Item# to location info

Post 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#.)
proxy3d
ScaleRichView Developer
Posts: 307
Joined: Mon Aug 07, 2006 9:37 am

Post 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;
Post Reply