TXLSFormulaDebugger class
TXLSFormulaDebugger analyzes a formula in one XLSX worksheet context and returns an owned TXLSFormulaDebugSession
The session combines the complete parsed expression tree with the actual evaluation order, intermediate values, dependency coordinates, selected lazy branches, skipped expressions, and the first error origin
The caller owns and must free every session returned by Analyze
Declaration
type
TXLSFormulaDebugger = class
constructor Create(Worksheet: TXLSXWorksheet);
function Analyze(const Formula: WideString):
TXLSFormulaDebugSession;
end;
Session members
| Formula | Normalized source without the optional leading equals sign |
| FinalValue | Calculated scalar value or standard Variant formula error |
| Nodes | Parsed nodes in parent-before-child order |
| Dependencies | Cell, range, or defined-name dependencies with resolved worksheet coordinates when available |
| StepNodes | Nodes in deterministic evaluation order, including skipped nodes |
| CurrentNode | Node selected by the interactive navigation cursor |
| ErrorOriginNodeId | Deepest node that originated the final formula error, or -1 when the final result is not an error |
| ErrorCode | Excel error code carried by the final error value |
| ErrorText | Excel display text such as #DIV/0! or #N/A |
Node diagnostics
Each TXLSFormulaDebugNode reports its parent, depth, source span, node kind, operator or function name, operand node identifiers, operand values, result value, evaluation index, state, selected branch, and error details
Node state is fdsPending, fdsEvaluated, fdsSkipped, or fdsError
Branch diagnostics distinguish true and false IF paths, value and fallback IFERROR or IFNA paths, and the selected CHOOSE, IFS, or SWITCH branch
Recovered inner errors remain visible on their nodes even when the final formula result is valid
Navigation
MoveFirstselects the first evaluation stepMoveNextandMovePreviousmove the current cursor without recalculatingSeekNodeselects one node by its stable session-local identifierResetclears the cursor while preserving all diagnostics
Example
Debugger := TXLSFormulaDebugger.Create(Sheet);
try
Session := Debugger.Analyze('=IF(A1=0,42,B1/C1)');
try
if Session.MoveFirst then
repeat
Writeln(Session.CurrentNode.Source);
until not Session.MoveNext;
finally
Session.Free;
end;
finally
Debugger.Free;
end;