fpspreadsheet: Fix crash when copying a formula to the clipboard (see https://forum.lazarus.freepascal.org/index.php/topic,41161.msg287786.html#msg287786)

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@6457 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz 2018-06-04 13:42:36 +00:00
parent 38001d24d7
commit fb9917e10c

View File

@ -1939,19 +1939,23 @@ end;
-------------------------------------------------------------------------------}
procedure TsWorksheet.CopyFormula(AFromCell, AToCell: PCell);
var
srcSheet, destSheet: TsWorksheet;
srcFormula, destFormula: PsFormula;
rpn: TsRPNFormula;
begin
if (AFromCell = nil) or (AToCell = nil) then
exit;
DeleteFormula(AToCell);
srcSheet := TsWorksheet(AFromCell^.Worksheet);
destSheet := TsWorksheet(AToCell^.Worksheet);
destSheet.DeleteFormula(AToCell);
if not HasFormula(AFromCell) then
exit;
srcFormula := FFormulas.FindFormula(AFromCell^.Row, AFromCell^.Col);
destFormula := FFormulas.AddFormula(AToCell^.Row, AToCell^.Col);
srcFormula := srcSheet.Formulas.FindFormula(AFromCell^.Row, AFromCell^.Col);
destFormula := destSheet.Formulas.AddFormula(AToCell^.Row, AToCell^.Col);
destFormula.Parser := TsSpreadsheetParser.Create(self);
srcFormula^.Parser.PrepareCopyMode(AFromCell, AToCell);