KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Utility method to convert 4D Write to 4D Write Pro table field
PRODUCT: 4D Write Pro | VERSION: 17 | PLATFORM: Mac & Win
Published On: October 12, 2021

If the database is still in 32-bit and using 4D Write in a table field, it will be necessary to create another object field in the table to store 4D Write Pro objects. To do this process, you can use the utility method where the 1st argument is a table pointer, the 2nd argument is the source 4D Write table field, and the 3rd argument will be the destination 4D Write Pro table field.

// Method: _convertWriteFieldToObject
// Description
// Method that will take a source 4D Write table field and convert it to 4D Write Pro object into destination table field
// Parameters
// $1 - Table pointer
// $2 - Source table field containing old 4D Write data (blob or picture)
// $3 - Destination table field where new 4D Write Pro object will be saved
// ----------------------------------------------------

C_POINTER($1;$table_ptr)
C_POINTER($2;$wrField_ptr)
C_POINTER($3;$wpField_ptr)
C_LONGINT($i)
C_LONGINT($offscreen_l)
C_BLOB($blob_b)

$table_ptr:=$1
$wrField_ptr:=$2
$wpField_ptr:=$3

ALL RECORDS($table_ptr->)

Case of
   : (Type($wrField_ptr->)=Is picture)
     For (i;1;Records in selection($table_ptr->))
       $offscreen_l:=WR New offscreen area
       WR PICTURE TO AREA ($offscreen_l;$wrField_ptr->)
       $blob_b:=WR Area to blob ($offscreen_l;1)
       $wpField_ptr->:=WP New($blob_b)
       SAVE RECORD($table_ptr->)
       WR DELETE OFFSCREEN AREA ($offscreen_l)
       NEXT RECORD($table_ptr->)
     End for
  
   : (Type($wrField_ptr->)=Is BLOB)
     For ($i;1;Records in selection($table_ptr->))
       $wpField_ptr->:=WP New($wrField_ptr->)
       SAVE RECORD($table_ptr->)
       NEXT RECORD($table_ptr->)
     End for
  
End case

ALERT("Conversion completed")