4D v16

WP New

Home

 
4D v16
WP New

WP New 


 

WP New {( source )} -> Function result 
Parameter Type   Description
source  String, BLOB, Object in String: 4D HTML source,
BLOB: 4D Write Blob document (.4w7/.4wt) or 4D Write Pro document (.4wp)
Object: a 4D Write Pro object range
Function result  Object in 4D Write Pro object

The WP New command creates and returns a 4D Write Pro object.

By default, if you omit the source parameter, the command returns an empty 4D Write Pro object.

You can also use the source parameter, in which case the new 4D Write Pro object will be filled with the contents of the source. You can pass:

  • a string parameter: In this case, you pass a 4D HTML source, i.e. a text exported by WP EXPORT VARIABLE with the wk web page html 4D option. This text can contain references (4D tags and expressions) and embedded images.
  • a blob parameter: In this case, you pass either:
    • a 4D Write Pro (.4wp) format document stored in a BLOB. For more information about the 4D Write Pro document format, please refer to .4wp document format.
    • a legacy 4D Write area loaded in a BLOB (BLOBs containing .4w7 or .4wt documents are supported). For a detailed list of 4D Write features that are currently supported in 4D Write Pro objects, please refer to the Importing 4D Write documents section.
      If you want to import a 4D Write document (.4w7 or .4wt) stored on disk, you can also consider using the WP Import document command.
  • an object parameter: In this case, you pass a 4D Write Pro range object. WP New will return a new document created from the specified range. Note that, if the range is not equal to the full document range, only the first section is exported and bookmarks are not exported, if any.

The returned object is a complete document that can be passed to the WP INSERT DOCUMENT command, for example.

You want to create an empty 4D Write Pro object:

 myWPObject:=WP New

You want to create a 4D Write Pro object containing a simple 4D expression reference:

 C_TEXT(myText)
 myText:="Today is "
 ST INSERT EXPRESSION(myText;"string(current date;System date long)";ST End text)
 myWPA:=WP New(myText)

You want to initialize your Write Pro area with a previously-created template:

  //Export template from an existing area
 C_TEXT(wpTemplate)
 WP EXPORT VARIABLE(myWPArea;wpTemplate;wk web page html 4D)
 
  // use the template for a new area
 C_OBJECT(myNewWPA)
 myNewWPA:=WP New(wpTemplate)

You want to import a 4D Write document stored in a 4D field of the current record into a new 4D Write Pro area:

 C_OBJECT(wpArea)
 wpArea=WP New([Templates]Reference_)

You have defined a template document with different preformatted parts, each of them being stored as a bookmark. When producing a final document from the template, you can extract any bookmark as a new document and insert it in the final document.
 

 ARRAY TEXT($_BookmarkNames;0)
 WP GET BOOKMARKS([TEMPLATES]WP;$_BookmarkNames//get the bookmarks from the template
 $targetRange:=WP New //create an empty document (will be the final document)
 
 $p:=Find in array($_BookmarkNames;"Main_Header") //handle the main header part
 If($p>0)
    $Range:=WP Get bookmark range(WParea;$_BookmarkNames{$p}) //select the range
    $RangeDoc:=WP New($Range//create a new document from the range
    WP INSERT DOCUMENT($targetRange;$RangeDoc;wk append+wk freeze expressions//wk append=after replacement, $targetRange is equal to end of replaced text
 End if



See also 

WP Import document
WP INSERT DOCUMENT

 
PROPERTIES 

Product: 4D
Theme: 4D Write Pro Language

This command can be run in preemptive processes

 
HISTORY 

New
Created: 4D v14 R5
Modified: 4D v15 R2
Modified: 4D v16

 
ARTICLE USAGE

4D Write Pro Reference ( 4D v16)