FormCalc Values and References
General FormCalc execution with EnableJavaScript implements explicit object references through Ref(value), while ordinary variable declarations and ordinary function arguments copy object values
Ref parameters and result
An accessor to an existing form object becomes an object handle; passing an existing handle preserves its identity, a null argument produces a null handle, and other scalar arguments return their scalar value
References provide ordinary node properties and methods such as rawValue, parent, name, resolveNode and resolveNodes
Scalar built-in arguments dereference handles, aggregate functions consume referenced values, and null handles retain null arithmetic and string semantics; Exists returns 0 for a null handle
var copied = target
target = 8
other = copied
var p = Ref(target)
p = 9
var q = p
q = 10
The first block preserves the previous value of target in copied; the second block writes target through two handles referring to the same object
Assignment and detachment
| Assignment | Behavior |
|---|---|
p = Ref(other) | Rebind p to the other object |
p = 5 when p is a reference | Write 5 to the referenced object and preserve the handle |
p = Null() when p is a reference | Clear the referenced object value and preserve the handle |
p = Ref(Null()) | Detach p and give the variable a null value |
p = 5 after detachment | Set the variable itself to 5 |
Variable redeclarations and user function arguments apply the same copy or reference rules; functions can receive, return and qualify explicit references
Equality and identity
Equality and inequality compare stable object identity when both operands are references; ordinary object operands compare their values, and the result is numeric 1 or 0
Two fields containing the same text compare equal by value, but Ref(first) eq Ref(second) returns 0 when they are different fields
Repeated instances and retained handles
A script object can retain an explicit handle across events; the handle resolves the current form node by stable identity, so reordering a repeated subform preserves the selected occurrence
Using a handle after its occurrence is removed raises an error; runtime transactions restore occurrence count, field values and script-object state when that error aborts the event
The runtime supplies stable template and data identities automatically; direct event callers that omit TXFAEventBinding.Identity receive a unique binding-index identity and should supply explicit stable identities when binding order changes
Migration
Earlier general execution retained ordinary node objects in variable declarations; replace var p=target with var p=Ref(target) when p must remain a node handle
General FormCalc equality results now use 1 and 0 instead of JavaScript boolean text; code that concatenated equality results should expect the numeric representation
Related APIs
Dynamic Eval, HPDFXFACompileFormCalcEvent, TXFAEventBinding and Interactive XFA Runtime