4D is finally working towards creating a new 4D Write and since 14 R5 we can actually use some of it.
Of course there is still quite a lot missing but with what we already have we can for example create nice looking E-Mails.
Now most of us have worked with 4D Write until now and moving to 4D WritePro requires quite a few conversion in order to prevent us from doing all again.
Converting a 4D Write Document to WritePro works fine, as long as you go through a document on Disk, using Blobs with WP New has yet to work reliably for me.
Using References or Expressions in 4D WritePro works surpassingly well, although the tools for manipulating these References and expressions are a bit lacking.
So I have created a few helper methods that I gladly share here:
First: Convert a stored 4DWrite Area (in a Blob) into a 4D WritePro HTLM Text:
// ----------------------------------------------------
// Method: Write_ToWritePro
// ----------------------------------------------------
// Call: WritePro:=Write_ToWritePro(WriteBlob{;StripPageMargins})
// ----------------------------------------------------
// UserName (OS): Alexander Heintz
// Date and Time: 03.08.15, 16:25:20
// ----------------------------------------------------
// Does:
// converts a 4D Write Document stored in a BLOB
// into a 4D WritePro Text "web page html 4D"
// as 4D WritePro retains the page margins of the original document
// you can opt to have those stripped
// ----------------------------------------------------
// Parameters:
// -> $1 blob the 4D Write Document
// -> $2 boolean strip the page margins of the 4D Write document
// <- $0 text the 4D WritePro Document
// ----------------------------------------------------
// Parameter Definition
C_TEXT($0)
C_BLOB($1)
C_BOOLEAN($2)
// ----------------------------------------------------
// Local Variable Definition
C_BOOLEAN($b_StripPageMargins)
C_LONGINT($l_Compressed)
C_OBJECT($o_wp_in)
C_OBJECT($o_wp_save)
C_TEXT($t_Content)
C_TEXT($t_DocPath)
C_BLOB($x_WriteBlob)
C_LONGINT($xwr_temp)
// ----------------------------------------------------
// Parameter Assignment
$x_WriteBlob:=$1
If (Count parameters>1)
$b_StripPageMargins:=$2
End if
// ----------------------------------------------------
BLOB PROPERTIES($x_WriteBlob;$l_Compressed)
If ($l_Compressed#Is not compressed)
EXPAND BLOB($x_WriteBlob)
End if
$t_DocPath:=HFS_tempdoc ("4W7") //replace with your preferred way to create a temp file
If (Test path name($t_DocPath)=Is a document)
DELETE DOCUMENT($t_DocPath)
End if
$xwr_temp:=WR New offscreen area
WR BLOB TO AREA ($xwr_temp;$x_WriteBlob)
WR SAVE DOCUMENT ($xwr_temp;$t_DocPath;"4WR7")
WR DELETE OFFSCREEN AREA ($xwr_temp)
$o_wp_in:=WP Import document($t_DocPath)
If ($b_StripPageMargins)
$t_Content:=ST Get text($o_wp_in)
$o_wp_save:=WP New
ST SET TEXT($o_wp_save;$t_Content)
WP EXPORT VARIABLE($o_wp_save;$t_Content;wp web page html 4D)
Else
WP EXPORT VARIABLE($o_wp_in;$t_Content;wp web page html 4D)
End if
$0:=$t_Content
Some of us store snippets of 4D Write Text for later use, these are retrieved with WR Get Styled Text. These also need to be transformed in to 4D WritePro, but again not as full documents but only snippets of styled text.
So here is
// ----------------------------------------------------
// Method: Write_ToWriteProSnippet
// ----------------------------------------------------
// Call: Write_ToWriteProSnippet
// ----------------------------------------------------
// UserName (OS): Alexander Heintz
// Date and Time: 05.08.15, 13:35:33
// ----------------------------------------------------
// Does:
// converts a snippet of 4D Write Text into
// a piece of styled Text
// ----------------------------------------------------
// Parameters:
// -> $1 type description
// ----------------------------------------------------
// Parameter Definition
C_BLOB($1)
C_TEXT($0)
// ----------------------------------------------------
// Local Variable Definition
C_OBJECT($o_WrProTemp)
C_TEXT($t_Content)
C_BLOB($x_Blob)
C_LONGINT($xwr_Temp)
// ----------------------------------------------------
// Parameter Assignment
$x_Blob:=$1
// ----------------------------------------------------
$xwr_Temp:=WR New offscreen area
WR INSERT STYLED TEXT ($xwr_Temp;$x_Blob)
SET BLOB SIZE($x_Blob;0)
$x_Blob:=WR Area To Blob ($xwr_Temp;1)
WR DELETE OFFSCREEN AREA ($xwr_Temp)
$t_Content:=Write_ToWritePro ($x_Blob)
$o_WrProTemp:=WP New($t_Content)
$t_Content:=ST Get text($o_WrProTemp;ST Start text;ST End text)
CLEAR VARIABLE($o_WrProTemp)
$0:=$t_Content
References and Expressions
I find it very helpful to be able to get a list with position of all references in my document so I can manipulate them easily. There currently is no Command in 4D WritePro to do this, so I created my own:
// ----------------------------------------------------
// Method: WritePro_GetExpressions
// ----------------------------------------------------
// Call: Count:=WritePro_GetExpressions(ObjectPointer;ArrayPtrPositions;ArrayPtrExrpessions)
// ----------------------------------------------------
// UserName (OS): Alexander Heintz
// Date and Time: 04.08.15, 13:02:02
// ----------------------------------------------------
// Does:
// fills the arrays passed with the locations and content
// of the expressions in the styled text
// ----------------------------------------------------
// Parameters:
// -> $1 pointer styled text or WP Area
// -> $2 pointer array long
// -> $3 pointer array text
// -> $0 longint number of expressions found
// ----------------------------------------------------
// Parameter Definition
C_POINTER($1)
C_POINTER($2)
C_POINTER($3)
C_LONGINT($0)
// ----------------------------------------------------
// Local Variable Definition
C_LONGINT($l)
C_LONGINT($l_DetCheckEnd)
C_LONGINT($l_EndSub)
C_LONGINT($l_Length)
C_LONGINT($l_Start)
C_LONGINT($l_StartSub)
C_POINTER($p_Area)
C_POINTER($p_Exp)
C_POINTER($p_Pos)
C_LONGINT($l_End)
// ----------------------------------------------------
// Parameter Assignment
$p_Area:=$1
$p_Pos:=$2
$p_Exp:=$3
// ----------------------------------------------------
$l_Start:=1
$l_Length:=Length(ST Get plain text($p_Area->))
If (ST Get content type($p_Area->;$l_Start;$l_Length)=ST Mixed type)
//split to 100 chars
While ($l_Start<$l_Length)
$l_StartSub:=$l_Start
$l_EndSub:=$l_StartSub+100
$l_EndSub:=Choose($l_EndSub>$l_Length;$l_Length;$l_EndSub)
$l_End:=$l_Start+100
If (ST Get content type($p_Area->;$l_Start;$l_End)=ST Mixed type)
//batches of 10
While ($l_StartSub<$l_EndSub)
$l_End:=$l_StartSub+10
If (ST Get content type($p_Area->;$l_StartSub;$l_End)=ST Mixed type)
$l_DetCheckEnd:=$l_StartSub+10
$l_DetCheckEnd:=Choose($l_DetCheckEnd>$l_Length;$l_Length;$l_DetCheckEnd)
For ($l;$l_StartSub;$l_DetCheckEnd)
$l_End:=$l+1
If (ST Get content type($p_Area->;$l;$l_End)=ST Expression type)
APPEND TO ARRAY($p_Pos->;$l)
APPEND TO ARRAY($p_Exp->;ST Get expression($p_Area->;$l;$l+1))
End if
End for
End if
$l_StartSub:=$l_StartSub+10
End while
End if
$l_Start:=$l_Start+100
End while
End if
$0:=Size of array($p_Pos->)
I hope this stuff proves useful to someone, comments welcome.
Many thanks. It helps me a lot to convert my old 4dWrite files.
You’re welcome.
Also, I will make most of my components available as source in the next few days, updated for V18, in project and binary mode.
I myself prefer the project mode, so many more options 🙂