fpspreadsheet: Fix missing error to be shown when a sheet containing a formula with circular reference is calculated.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@3896 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2015-01-24 15:44:54 +00:00
parent d9343190a4
commit 9d89f1dcf3
2 changed files with 15 additions and 7 deletions

View File

@ -795,6 +795,7 @@ type
end; end;
EExprParser = class(Exception); EExprParser = class(Exception);
ECalcEngine = class(Exception);
function TokenName(AToken: TsTokenType): String; function TokenName(AToken: TsTokenType): String;
function ResultTypeName(AResult: TsResultType): String; function ResultTypeName(AResult: TsResultType): String;
@ -881,7 +882,7 @@ resourcestring
ErrInvalidArgumentCount = 'Invalid argument count for function %s'; ErrInvalidArgumentCount = 'Invalid argument count for function %s';
SErrInvalidResultType = 'Invalid result type: %s'; SErrInvalidResultType = 'Invalid result type: %s';
SErrNotVariable = 'Identifier %s is not a variable'; SErrNotVariable = 'Identifier %s is not a variable';
SErrCircularReference = 'Circular reference found when calculating worksheet formulas'; SErrCircularReference = 'Circular reference found when calculating worksheet formula in cell %s';
{ --------------------------------------------------------------------- { ---------------------------------------------------------------------
Auxiliary functions Auxiliary functions
@ -3846,7 +3847,7 @@ begin
csNotCalculated: csNotCalculated:
Worksheet.CalcFormula(cell); Worksheet.CalcFormula(cell);
csCalculating: csCalculating:
raise Exception.Create(SErrCircularReference); raise ECalcEngine.CreateFmt(SErrCircularReference, [GetCellString(cell^.Row, cell^.Col)]);
end; end;
Result.ResultType := rtCell; Result.ResultType := rtCell;

View File

@ -1386,14 +1386,21 @@ begin
begin begin
formula := ACell^.FormulaValue; formula := ACell^.FormulaValue;
parser.ActiveCell := nil; parser.ActiveCell := nil;
end end else
else
begin begin
formula := ACell^.SharedFormulaBase^.FormulaValue; formula := ACell^.SharedFormulaBase^.FormulaValue;
parser.ActiveCell := ACell; parser.ActiveCell := ACell;
end; end;
parser.Expression := formula; try
res := parser.Evaluate; parser.Expression := formula;
res := parser.Evaluate;
except
on E:ECalcEngine do
begin
Workbook.AddErrorMsg(E.Message);
Res := ErrorResult(errIllegalRef);
end;
end;
case res.ResultType of case res.ResultType of
rtEmpty : WriteBlank(ACell); rtEmpty : WriteBlank(ACell);
rtError : WriteErrorValue(ACell, res.ResError); rtError : WriteErrorValue(ACell, res.ResError);
@ -1450,7 +1457,7 @@ begin
node := FCells.FindSuccessor(node); node := FCells.FindSuccessor(node);
end; end;
// Step 2 - calculate cells. If a not-calculated cell is found it is // Step 2 - calculate cells. If a not-yet-calculated cell is found it is
// calculated and then marked as such. // calculated and then marked as such.
node := FCells.FindLowest; node := FCells.FindLowest;
while Assigned(Node) do begin while Assigned(Node) do begin