KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Get contents of Write Pro bookmark
PRODUCT: 4D | VERSION: 16 | PLATFORM: Mac & Win
Published On: December 8, 2016

Bookmark can store information of what was selected in the Write Pro object. The following method can extract the bookmark contents in plain text:

// --------------------------------------------------------------------------------
// Name: WP_GET_BOOMARK_CONTENTS
// Description: Method will extract the contents of the Write Pro object and
// return the Bookmark contents in plain text.
// Input:
// $1 (POINTER) - Pointer to the 4D Write Pro object
// $2 (TEXT) - Name of the Bookmark
// Output:
// $0 (TEXT) - Extracted text from the Bookmark of the Write Pro object
// --------------------------------------------------------------------------------
C_POINTER($1;$wpPtr)
C_TEXT($2;$bookMark)
C_TEXT($0)
C_TEXT($str;$wStr;$tStr)
C_LONGINT($pos;$pos1;$pos2;$posBodyEnd)
C_OBJECT($wpRange)

If (Count parameters=2)
    $wpPtr:=$1
    $bookMark:=$2
   
    WP EXPORT VARIABLE($wpPtr->;$str;wk web page html 4D)
   
    $pos:=Position("<body>";$str)+6
    $posBodyEnd:=Position("</body>";$str)
    $tStr:=""
   
    Repeat
     $pos1:=Position(">";$str;$pos)+1
     $pos2:=Position("<";$str;$pos1)
     $wStr:=Substring($str;$pos1;$pos2-$pos1)
     $tStr:=$tStr+$wStr
     $pos:=$pos2+1
    Until ($posBodyEnd=$pos2)
   
    $tStr:=Replace string($tStr;"\t";"")

    // Getting the range
    $wpRange:=WP Get bookmark range($wpPtr->;$bookMark)
    $rangeStart:=OB Get($wpRange;"rangeStart")
    $rangeEnd:=OB Get($wpRange;"rangeEnd")
   
    $0:=Substring($tStr;$rangeStart;$rangeEnd-$rangeStart)
End if


Here is the highlighted area that will be saved as a bookmark called "myBookmark":




Using the method in extracting the bookmark "myBookmark":

C_TEXT($wpText)

$wpText:=WP_GET_BOOMARK_CONTENTS (->WriteProArea;"myBookmark")


Output displayed: