HotXLS Docs

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

FormulaNormalized source without the optional leading equals sign
FinalValueCalculated scalar value or standard Variant formula error
NodesParsed nodes in parent-before-child order
DependenciesCell, range, or defined-name dependencies with resolved worksheet coordinates when available
StepNodesNodes in deterministic evaluation order, including skipped nodes
CurrentNodeNode selected by the interactive navigation cursor
ErrorOriginNodeIdDeepest node that originated the final formula error, or -1 when the final result is not an error
ErrorCodeExcel error code carried by the final error value
ErrorTextExcel 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

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;

See also