When upgrading a 4D database, it is important to place consideration on 4D Write documents. With the latest versions of 4D, the 4D Write plugin is not supported as such it will be difficult to interact and manipulate documents using 4D Write commands. It is best to prepare the documents in a version that supports the 4D Write plugin before moving to the latest version of 4D.
Some items to consider are:
- Making sure that images in the documents are in a format supported in the latest version of 4D. Some formats, such as PICT, format images are not supported in the latest versions of 4D.
- Making sure that the document is in a format that can be interacted with 4D Write Pro. 4D Write Pro can open a 4D Write document with the WP New command. This will open the 4D Write document as a 4D Write Pro document converting it in the process. However, this command is only compatible with a 4D Write document as a .4wp file or as a blob using the .4w7 or .4wt format. A popular method of storing 4D Write document in a database was as a picture field. It would be best to use the 4D Write commands to convert the picture formatted 4D Write document into one of the compatible formats.
- Using WP New to convert the document, there may be slight differences between the resulting conversion. Due to this, it could be helpful to maintain the old version or generate a PDF printed render.
There are various ways to perform the conversion. In all cases, it is always best to maintain backups and work with a disposable copy in case mistakes are made.
An example process with a 4D Write document stored in a Picture Field would be:
1) In the current version export each document onto the disk using the UUID of the record as a name.
2) In the converted database add a new object field to the table.
3) Import each document to the table using the UUID.
Below are example code for this process
Example Export Code:
ALL RECORDS([myTable]) $path_t:=System folder(Desktop)+"WriteDocs"+Folder separator For($i;1;Records in selection([myTable])) If(Picture size([myTable]WriteDocPic])>0) $wra_l:=WR New offscreen area WR PICTURE TO AREA ($wra_l;[myTable]WriteDocPic]) WR SAVE DOCUMENT ($wra_l;$path_l+[myTable]UUID;.".4w7") End if Next Record([myTable]) End for |
Example Import Code:
ALL RECORDS([myTable]) $path_t:=System folder(Desktop)+"WriteDocs"+Folder separator For($i;1;Records in selection([myTable])) If(Test path name($path_t+[myTable]UUID)=Is a document) [myTable]WPDocObj := WP New($path+[myTable]UUID) Else [myTable]WPDocObj := WP New End if Next Record([myTable]) End for |
There are other strategies to convert and maintain 4D Write Documents but the above are some suggestions and an example to get started.