KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Replacing an anchor picture in 4D Write Pro
PRODUCT: 4D | VERSION: 17 R | PLATFORM: Mac & Win
Published On: March 25, 2019

Using the WP add picture for an anchor type of pictures but one may want to replace pictures in the future. Here is a utility method to replace exisiting anchor pictures:

//---------------------------------------------------------------------------------
// Name: WP_REPLACE_ANCHOR_PICTURE
// Description: Method will replace an anchor picture in 4D WritePro.
//
// Parameters:
// $1 (POINTER) - 4D Write Pro obj
// $2 (TEXT) - ID of the picture object
// $3 (Picture) - Picture to replace
// --------------------------------------------------------------------------------
C_POINTER($1;$wpObj)
C_TEXT($2;$ID)
C_PICTURE($3;$picLoc)
C_LONGINT($i)
C_COLLECTION($queryCol)

If (Count parameters=3)
  $wpObj:=$1
  $ID:=$2
  $picLoc:=$3
  
  $queryCol:=WP Get elements($wpObj->;wk type image).query("id = :1";$ID)

  If ($queryCol.length>0)
    WP SET ATTRIBUTES($queryCol[0];wk image;$picLoc)
  End if
End if


Here is an anchor picture for example on a header:




Using the method replaces an existing anchor picture:

C_TEXT($locPic)
C_PICTURE($picture)

$locPic:=Get 4D folder(Database folder)+"scenery2.png"
READ PICTURE FILE($locPic;$picture)
WP_REPLACE_ANCHOR_PICTURE (->WriteProArea;"Img1";$picture)