Setting up custom event hyperlinks
The custom event hyperlinks are defined the same way as normal hyperlinks: you add #UR A HREF= to the label or field comment, followed by “vfpev” as a “protocol”, followed by a FoxPro expression to evaluate.
Example: Hello world
#UR A HREF="vfpev:\\messagebox('Hello world')"
If you add this to a field on your report a “Hello world” messagebox pops up whenever you click on that field.
Please be aware that the text following after HREF= is evaluated during the report execution, at the time the field is about to be rendered. The result is then stored with that particular field and evaluated again when users click on the field. For example, if you need to call your function with a customer ID as a parameter (for example stored in customers.cusID as an integer value), you use something like this:
#UR A HREF="vfpev:\\myfunction("+trans(customers.cusID)+")"
During the report generation the customers.cusID expression is evaluated and the results (e.g. myfunction(1), myfunction(2), etc.) are stored with the individual fields. Myfunction function with the stored parameter is then called when users click on the field.
Accessing the calling previewer
In case the custom event should result in running a new report, the routine that processes the new report may want to previewer the resulting output in the original previewer, in which the click event occurred. In that case, you can use thisviewer variable as the previewer reference. For example, the following hyperlink definition would be sending the previewer reference as the second parameter of runreport method:
#UR A HREF="vfpev:\\runreport('"+allt(customerid_a)+"',thisviewer)"
Drilldown solution example
(The following example is available in the DrilldownSample subdirectory of the evaluation as well as commercial package).
The sample solution consists of three reports:
- A customer index page followed by a brief list of customers. For each customer there is a list of last three orders, total number of orders and the total turnover:
- When you click on the customer name, a new report with customer details is generated, listing all customer’s orders:
- By clicking on an order number, an order detail report is generated:
Whenever a new report is generated, it is added as a new page to the previewer container:
Here is the full source code:
As you can see, the code is first called without parameters, which automatically runs the first report (customer list). Then the same code is then called (recursively – as the previewer is in modal mode) from the previewer when users click on the custom event with parameters controlling which report should be run, which parameters should be used for the select statement and what should be the caption of the corresponding page in the previewer.
The report fields’ comments are defined as follows:
#UR A HREF="vfpev:\\runreport(2,'"+allt(customerid_a)+"',thisviewer)"
#UR A HREF="vfpev:\\runreport(3,"+allt(str(orderid_a))+",thisviewer)"