From 872c04e07ad6512384ff52190423eb3adafbeff0 Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Thu, 3 Sep 2020 20:35:33 +0000 Subject: [PATCH] fpspreadsheet: Fix worksheetgrid writing edited cell to wrong cell when grid is on MDI form (issue #37596, https://forum.lazarus.freepascal.org/index.php/topic,51066.0.html). git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7642 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- .../source/visual/fpspreadsheetgrid.pas | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/components/fpspreadsheet/source/visual/fpspreadsheetgrid.pas b/components/fpspreadsheet/source/visual/fpspreadsheetgrid.pas index b6c001001..448a34bed 100644 --- a/components/fpspreadsheet/source/visual/fpspreadsheetgrid.pas +++ b/components/fpspreadsheet/source/visual/fpspreadsheetgrid.pas @@ -291,6 +291,7 @@ type procedure DrawRow(aRow: Integer); override; procedure DrawSelection; procedure DrawTextInCell(ACol, ARow: Integer; ARect: TRect; AState: TGridDrawState); override; + procedure EditorDoGetValue; override; procedure ExecuteHyperlink; procedure GenericPenChangeHandler(Sender: TObject); function GetCellHeight(ACol, ARow: Integer): Integer; @@ -3372,6 +3373,7 @@ var cell: PCell; msg: String; begin + { if (not EditorShowing) and FEditing then begin if not ValidFormula(FEditText, msg) then @@ -3396,6 +3398,32 @@ begin end; FEditing := false; FEnhEditMode := false; + } + inherited; +end; + +{@@ ---------------------------------------------------------------------------- + Is called when editing is complete; checks whether input is valid already + have been done. + The method must transfer the edited cell text to the worksheet cell +-------------------------------------------------------------------------------} +procedure TsCustomWorksheetGrid.EditorDoGetValue; +var + cell: Pcell; +begin + if (Editor<>nil) and Editor.Visible and (FOldEditorText <> FEditText) then + begin + cell := Worksheet.GetCell(GetWorksheetRow(Row), GetWorksheetCol(Col)); + if Worksheet.IsMerged(cell) then + cell := Worksheet.FindMergeBase(cell); + if (FEditText <> '') and (FEditText[1] = '=') then + Worksheet.WriteFormula(cell, Copy(FEditText, 2, Length(FEditText)), true) + else + Worksheet.WriteCellValueAsString(cell, FEditText); + FEditText := ''; + FOldEditorText := ''; + end; + inherited; end; function TsCustomWorksheetGrid.EditorByStyle(Style: TColumnButtonStyle): TWinControl; @@ -5395,7 +5423,6 @@ var err: String; begin // Checking validity of formula in current cell - if Assigned(Worksheet) and EditorMode then begin if not ValidFormula(FEditText, err) then begin FGridState := gsNormal; @@ -5405,7 +5432,6 @@ begin end; end; - Result := inherited; if Result and Assigned(Worksheet) and Worksheet.IsProtected then