Links in 4D Write Pro documents

Automatically translated from English

As a developer or end user, you know how convenient hyperlinks can be. Without them, you would need to know the URL for every page on the internet! They let you turn your text or pictures into links to allow easy transitions from one place (e.g., a 4D Write Pro document) to another (typically a website).

What if links could offer more? What if they could launch the execution of 4D code or simply move the cursor to a different area in the same document? They can!

You can insert links in your documents with the WP Set attribute command, but only URLs. The new WP SET LINK command allows you to set URLs too (easier), but also gives you the ability to invoke a method from your application (with parameters!) or target bookmarks from your document!

FOUR kinds of links

  • The first link types works similar to WP Set attributes ($range;wk link url…) except the parameter is now an object instead of a string.

$link:=New object("url";"www/4d.com")
WP SET LINK($target;$link)

  • The second link type allows creating links that, when clicked, will run a 4D Method. The method can even receive a text or numeric parameter. Just be sure that the method is set as “allowed” with the SET ALLOWED METHODS command.

$link:=New object("method";"myAlert";"parameter";"Hello world!")
WP SET LINK($target;$link)

  • The third link type allows defining links to external documents (on disk). The documents must be 4D Write or 4D Write Pro documents in order to be imported. They will replace the current document.

$link:=New object("url";"HelloWorld.4WP)
WP SET LINK($range;$link)

  • The fourth link type is new: A link can be set to a bookmark. Of course, the bookmark must have already been created in your document. When the link is clicked, the cursor will automatically “jump” to the bookmark!

$link:=New object("bookmark";"chapterOne")
WP SET LINK($target;$link)

Have you noticed that the first parameter is a target? It can be either a range or any other valid object of your document (like a paragraph or any element like a picture). This will make your programming much easier to write and maintain!

Now that links have been set, let’s get them!

As you can guess, the new WP SET LINK command comes with a sibling: WP Get links.

In a single call, this command returns a collection of all the links in a document. Each link of this collection is an object with a description of the link in its attributes.

The attributes are:

link.url (for URL links)
link.bookmark (for bookmark links)
link.method (for method links)
link.parameter (if any)
link.range (information such as.start, .end, etc.)

Below is an HDI to demonstrate all these possibilities :

Database example

More details can be found on the doc center.

Roland Lannuzel

• Product Owner & 4D Expert •

After studying electronics, Roland went into industrial IT as a developer and consultant, building solutions for customers with a variety of databases and technologies. In the late 80’s he fell in love with 4D and has used it in writing business applications that include accounting, billing and email systems.

Eventually joining the company in 1997, Roland’s valuable contributions include designing specifications, testing tools, demos as well as training and speaking to the 4D community at many conferences. He continues to actively shape the future of 4D by defining new features and database development tools.