4D Write Expressions -> 4D Write Pro Formulas

We are converting 4D Write merge documents to 4D Write Pro.
We have a number of formulas that are called, and in turn fill in several variables, but don’t return a value.

MyFormula(“200”;current date) fills in vHeader, vBody, vTotals, in a text grid context.
We may call this formula several times in a merge document, repeatedly using the same variables:

«MyFormula(“200”;current date)»
Category A number «vTotals»
«MyFormula(“201”;current date)»
Category B number «vTotals»
«MyFormula(“201”;current date)»
Category C number «vTotals»

vTotals has a different number in each row.
When converting a 4D Write document to 4D Write Pro, it behaves differently.

In 4D Write Pro, we see the number from the first call in each row.
However, we use a logging routine out to a disk file, and the formula is calculating correctly - only the contents of the document are wrong.

Is this technique not possible in 4D Write Pro?

We are currently on v17.3hf3, Windows, getting ready for 64-bit on the client side.
Part of this process is building some automated tests to run our customers’ existing documents in 4D Write and 4D Write Pro, and diffing them to make sure they are the same.

Thanks,

Jim

I really do not have an answer for that…

if each “row” in the merge is a WP document, perhaps you need to clone the WP object for every instance to trigger reevaluation.

or, maybe you need to trick WP by changing the vTotals formula to vTotals+0 or something like that.

if neither works, I guess you need to replace the embedded process variable with a formula that returns a value.

I understand that this seemed to work before, but I’m not sure it was the intended behaviour in 4D Write. Don’t want to go so far to name it bug, but at least missing optimisation and not good implementation.

I never tried that, as I never expected it to work. Either a formula returned the result and that returned result was used, or if I needed to repeatly (in a loop) insert values, I used “freeze” inside the loop to convert the variable to text.

4D Write Pro is designed for larger documents as 4D Write was.
As such, it is more optimised, trying to avoid unnecessary calculations. 4D Write often happend to call functions several times, slowing everything down.

I think in your case, MyFormula… should return the value, not set a global variable which is used below the formula.

OK - I understand. At least the old 4D Write was stable with its undocumented behavior all these years!
We went to some lengths in code to avoid the unnecessary calculations in WR7.

Tentative solution to move to Write Pro. This is meant for existing merge documents already in production.

When converting documents from WR to WP

  1. Read all formulas from WR into a collection containing:
  • formula to be executed
  • unique variable of proper type (may require some manual mapping of types)
  • and/or a unique name for the formula
  1. add collection to WP object (I think we are allowed?), or another object on same record
  2. in WP document replace formulas with the unique variables or function calls

When running merge process with WP, execute all the formulas filling their variables, then run ST FREEZE EXPRESSIONS or the newer command in v18+.

Instead of unique variables, replace with old expressions with wrappers that behave like functions.
ft(“TextFuncName”)
fn(“NumFuncName”)
etc.
In the case of an old function filling several variables, we would make a unique call for each use of a variable.

We will need a UI to access the stored functions if we ever need to edit the functions, but we planned on something like this for a better system with WR Pro anyway. Some of the old documents are a nightmare to manage, and may have even a hundred expressions in them.

Does this concept make sense?

Thanks,

Jim