An Anchor is one of the elements in the hyperlink system which enables jumping to any element connected to the finished report’s object by clicking on it (in the preview window).
Anchor can be set via the “Engine.AddAnchor” method. Anchor has a name and a position within a report page. To jump to an anchor with a specified name, type the following line into the URL property of any report object:
#AnchorName
or
#[AnchorName]
In the second case FastReport substitutes a value for the expression.
Clicking on the object executes a jump to that part of the report where the anchor was added.
Use anchors when constructing a “Contents” table, for example with links to corresponding chapters. Let's illustrate this in the following example. First we need the familiar “Customer” table.
Our report will be a multi-page one (with two design pages). We will place the “Contents” table on the first page and the list of clients on the second page. Clicking on any Content line executes a jump to the corresponding report element.
The first design page:
Place the following text in the URL property of the “Text” object contained in the data-band
#[Customers."Company"]
and set the font properties to blue and underlined, to simulate the look of a hyperlink.
The second design page:
To add an anchor, create a “MasterData2.OnBeforePrint” event handler in the script:
PascalScript:
procedure MasterData2OnBeforePrint(Sender: TfrxComponent);
begin
Engine.AddAnchor(<Customers."Company">);
end;
C++ Script:
void MasterData2OnBeforePrint(TfrxComponent Sender)
{
Engine.AddAnchor(<Customers."Company">);
}
That is all that is needed. Preview the report and make sure that the “hyperlinks” work.
The last thing to be mentioned is the “Engine.GetAnchorPage” function. This function returns the number of the page on which the corresponding anchor was added and is useful when creating the “Contents” table. The report must be a two-pass one, otherwise this function cannot be used.
|