KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: 4D Write Pro Double Click Expression to Modify
PRODUCT: 4D | VERSION: 18 R | PLATFORM: Mac & Win
Published On: August 3, 2020

In 4D Write it was possible to modify an expression by double clicking it. In 4D Write Pro this is not a default feature, however it is posible to implement this feature.

  // Apply to WP Area's Object Method for On Double Clicked Event
C_OBJECT($wpSelection_o)
C_COLLECTION($wpFormulas_c)
C_TEXT($newFormula_t)

$wpSelection_o:=WP Selection range(Self->)
$wpFormulas_c:=WP Get formulas($wpSelection_o)

If ($wpFormulas_c.length=1)
   If (($wpSelection_o.start=$wpFormulas_c[0].range.start) & ($wpSelection_o.end=$wpFormulas_c[0].range.end))
    $newFormula_t:=$wpFormulas_c[0].formula.source

  // EDIT FORMULA must have a table passed as the first parameter modify this below to best reflect a table associated with the process
    EDIT FORMULA([Table_1];$newFormula_t)
    If (OK=1)
      WP INSERT FORMULA($wpSelection_o;Formula from string($newFormula_t);wk replace)
    End if
  End if
End if

With the code added to a 4D WP area's On Double Clicked event, when an expression is double clicked on, the expression editor will open up with the expression displayed and can be modified from the editor.

NOTE: The sample code uses new commands introduced in 4Dv18R2, WP Get formulas, WP INSERT FORMULA, and Formula from string. This can be substituted with the deprecated in v18R2 use of ST commands.