Retrieve URL from Item

General TRichView support forum. Please post your questions here
Post Reply
Jim Knopf
Posts: 241
Joined: Mon Dec 30, 2013 10:07 pm
Location: Austria
Contact:

Retrieve URL from Item

Post by Jim Knopf »

Perhaps it is too simple for my complicated thinking ...

Iterating items (export text to ebook) I have to get the url of the particular item. Tried with GetJumpPointLocation, but the id seems not to be the current item number.

Code: Select all

for i := 0 to rvEdit.ItemCount-1 do
  // URL of item i := ...?
end;
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

URLs are stored in items tags. By default, tags contain only URLs, so you can simply use rvEdit.GetItemTag(i).


Note 1: you should check if the item is a hyperlink. There are many types of items that can be hyperlinks:
- text (linked to textstyle having Jump=True)
- label items (and all items inherited from them, including numbering sequences, notes), linked to textstyles having Jump=True)
- tabs linked to textstyles having Jump=True
- hot pictures
- hotspots
Instead of checking all these types, it's simpler to use the undocumented method:
IsHyperlink := rvEdit.GetItem(i).GetBoolValueEx(rvbpJump, rvEdit.Style)

Note 2: If you use a simple cycle through rvEdit items, links in table cells will not be iterated. You need to use either a recursive procedure or undocumented EnumItems method. The latter is used in the "list of hyperlinks" demo: http://www.trichview.com/forums/viewtopic.php?t=397

The example of a recursive procedure is below.

Code: Select all

uses RVItem, CRVData, RVTable;

procedure EnumLinks(RVData: TCustomRVData);
var i,r,c: Integer;
  Table: TRVTableItemInfo;
begin
  for i := 0 to RVData.ItemCount-1 do
    if RVData.GetItem(i).GetBoolValueEx(rvbpJump, RVData.GetRVStyle) then begin
      // the link target is RVData.GetItemTag(i)
    end
  else if RVData.GetItemStyle(i)=rvsTable then begin
      Table := TRVTableItemInfo(RVData.GetItem(i));
      for r := 0 to Table.RowCount-1 do
        for c := 0 to Table.ColCount-1 do
          if Table.Cells[r,c]<>nil then
            EnumLinks(Table.Cells[r,c].GetRVData);
    end;
end;
Jim Knopf
Posts: 241
Joined: Mon Dec 30, 2013 10:07 pm
Location: Austria
Contact:

Post by Jim Knopf »

Sergey Tkachenko wrote:URLs are stored in items tags. By default, tags contain only URLs, so you can simply use rvEdit.GetItemTag(i).
Thanks, I found out in the meantime. But I thougt it's so simple, There's a catch ;)
Sergey Tkachenko wrote: Instead of checking all these types, it's simpler to use the undocumented method:
IsHyperlink := rvEdit.GetItem(i).GetBoolValueEx(rvbpJump, rvEdit.Style)
Thanks, very helpful!
Sergey Tkachenko wrote:Note 2: If you use a simple cycle through rvEdit items, links in table cells will not be iterated. You need to use either a recursive procedure or undocumented EnumItems method. The latter is used in the "list of hyperlinks" demo: http://www.trichview.com/forums/viewtopic.php?t=397
Fortunately there are no tables ...
Post Reply