KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Renaming an anchor ID
PRODUCT: 4D | VERSION: 17 R | PLATFORM: Mac & Win
Published On: February 28, 2019

When adding anchor picture to 4D Write Pro with WP Add picture, the naming convention for the ID will be "Img1, Img2, ...". This ID name can be change with the following utility method:

//---------------------------------------------------------------------------------
// Name: WP_RENAME_ANCHOR_ID
// 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 (TEXT) - New ID of the picture object
// --------------------------------------------------------------------------------
C_POINTER($1;$wpObj)
C_TEXT($2;$ID)
C_TEXT($3;$newID)
C_LONGINT($i)
C_COLLECTION($docElements)

If (Count parameters=3)
  $wpObj:=$1
  $ID:=$2
  $newID:=$3
  
  $docElements:=WP Get elements($wpObj->;wk type image)
  
  For ($i;0;$docElements.length-1)
  
    If ($docElements[$i].id=$ID)
      WP SET ATTRIBUTES($docElements[$i];wk id;$newID)
    End if
  
  End for
  
End if


Here is example of the anchor image ID:




Here is an example of the method changing the ID:
WP_RENAME_ANCHOR_ID (->WriteProArea;"Img1";"StopImg")

Here is the result: