We’ve received several customer requests to provide the ability to use the 4D Write Pro template with headers and footers to create other documents based on this template. Well, we heard you and this is available in 4D v16 R5.
A new set of commands have been added to 4D Write Pro to fulfill this need. Some of these commands can be used to get references of headers, body and footers inside documents. Others are handy to get a reference to the frame (header, footer, etc.) where the cursor is currently located, or to set the cursor into a specific frame.
Get a reference to headers, footers or body
New 4D commands – WP Get header, WP Get body and WP Get footer – have been added so that developers can get a reference to any header or footer for the document or for a specific section.
These references can then be used to get associated ranges, create documents, etc. The final goal is to copy the content of any frame (fully or partially) and paste it inside any other frame of the same document or any other new or existing one.
Code sample
// Get the header from a template and put it in the header of the main document
$source:=WP Get header(mytemplate;1) // first section
$rangeSource:=WP Get range($source;wk start text;wk end text)
$tempoc:=WP New($rangeSource)
$target:=WP Get header(myDocument;1) // first section
$rangeTarget:=WP Get range($target;wk start text;wk end text)
WP INSERT DOCUMENT($rangeTarget;$tempoc;wk replace)
Move the cursor to a specific frame
Upon creating elaborate documents by programming, you may want to successively put some information first in the header, then in the footer, and finally go back to fill the document body. It basically means that you need have a means to navigate in the different document frames.
The WP Get frame command is used to get the reference to the frame where the cursor is currently located: header, first header, body, first footer, etc. The WP SET FRAME command does the opposite job. It places the cursor inside a specific frame as long as this frame exists in the document.
Code samples
Let’s say you want to move the cursor to the main header:
WP SET FRAME(*;"WParea";wk current section default header)
If you want to make sure that the user has set the cursor in a header or footer:
$frame:=WP Get frame(*;"WParea")
If($frame=wk body)
ALERT("Please select a footer or a header")
End if