| 4D v20WP SET LINK | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 
 | 
    4D v20
 WP SET LINK 
         | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| WP SET LINK ( targetObj ; linkObj ) | ||||||||
| Parameter | Type | Description | ||||||
| targetObj | Object |   | Range or element or 4D Write Pro document | |||||
| linkObj | Object |   | Hyperlink value | |||||
The WP SET LINK applies a hyperlink reference to the targetObj. Links to URLs, 4D methods, and bookmarks, are supported. The link triggers an action when the user clicks on it (or uses Ctrl+click on Windows or Cmd+click on macOS if the text is not read-only for opening URLs).
In targetObj, pass the 4D Write Pro object where the link will be applied. You can pass:
For example, if you pass a header, the entire contents of the header will be displayed as a hyperlink. When inserting links in your documents, 4D Write Pro applies the following rules:
In the linkObj parameter, pass an object that describes the hyperlink. It must contain only one the following properties (except the parameter property which can be used in conjunction with the method property):
| Property | Type | Description | Hyperlink action | ||||||||||||||||||||||||
| url | Text | Destination for a URL type hyperlink (encoded url). | 
 | ||||||||||||||||||||||||
| bookmark | Text | Bookmark name | Accesses the specified bookmark in the current document. (See Bookmark commands) | ||||||||||||||||||||||||
| method | Text | Project method name - method must exist and be allowed with the SET ALLOWED METHODS command. | Executes the 4D method  when clicked. The method automatically receives two parameters in $1 and $2: 
 | ||||||||||||||||||||||||
| parameter | Text | Number | Used only with a method type link, not mandatory if the method does not require parameter. Contains an additional parameter to send to the method. | Received in $2.parameter within the method | 
Notes:
You want to add a link to your website in the footer area of your document:
 C_OBJECT($footer)
 $footer:=WP Get footer(WPArea;1)
 WP SET TEXT($footer;"Please visit our website";wk replace)
 WP SET LINK($footer;New object("url";"http://www.4d.com"))You want to create a table of contents with links using all of the bookmarks in your document:
 C_LONGINT($i;$n;$p;$memoStart)
 C_OBJECT($range;$link;$toc;$tocRange;$positionInfo;$target)
 C_TEXT($text)
 
 ARRAY TEXT($_bookmarks;0)
 WP GET BOOKMARKS(WParea1;$_bookmarks) //find all the bookmarks
 
 $n:=Size of array($_bookmarks)
 If($n>0)
    $tocRange:=WP Text range(WParea1;wk start text;wk start text) //find the beginning of the text
    WP INSERT BREAK($tocRange;wk page break;wk append;wk exclude from range) //add a page break before the text
 
    For($i;1;$n) // Insert the table of contents and links
       $range:=WP Bookmark range(WParea1;$_bookmarks{$i})
       $positionInfo:=WP Get position($range)
       $memoStart:=$tocRange.end
       WP SET TEXT($tocRange;Char(Tab)+$_bookmarks{$i}+Char(Tab)+String($positionInfo.page);wk append;wk include in range)
 
       $target:=WP Text range($tocRange;$memoStart+1;$memoStart+1+Length($_bookmarks{$i}))
       $link:=New object("bookmark";$_bookmarks{$i})
       WP SET LINK($target;$link)
       WP INSERT BREAK($tocRange;wk line break;wk append;wk include in range)
    End for
 End ifYou want to set a link to a 4D method on each "4D" string in the document:
 C_TEXT($text,$find)
 C_LONGINT($p)
 C_OBJECT($range;$link)
 
 $text:=WP Get text(wpArea;wk expressions as value) //retrieves all text in document
 
 $find:="4D" //target for link
 
 $p:=Position($find;$text) //loop through text to find all instances of the target
 If($p>0)
    $range:=WP Text range(wpArea;$p;$p+Length($find)) //set the length of the target
  //create the link object
    $link:=New object("method";"myAlert";"parameter";"4D rocks!") //Don't forget to authorize with SET ALLOWED METHODS  
 
    WP SET LINK($range;$link)
 End if
	Product:  4D
	Theme:  4D Write Pro Language
	Number:  
        1642
        
        
        
	
	Created:  4D v17 R5
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	4D Write Pro Reference ( 4D v20)
	
	
	
 Add a comment
Add a comment