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
This commit is contained in:
wp_xxyyzz
2020-09-03 20:35:33 +00:00
parent b02b245683
commit 872c04e07a

View File

@ -291,6 +291,7 @@ type
procedure DrawRow(aRow: Integer); override; procedure DrawRow(aRow: Integer); override;
procedure DrawSelection; procedure DrawSelection;
procedure DrawTextInCell(ACol, ARow: Integer; ARect: TRect; AState: TGridDrawState); override; procedure DrawTextInCell(ACol, ARow: Integer; ARect: TRect; AState: TGridDrawState); override;
procedure EditorDoGetValue; override;
procedure ExecuteHyperlink; procedure ExecuteHyperlink;
procedure GenericPenChangeHandler(Sender: TObject); procedure GenericPenChangeHandler(Sender: TObject);
function GetCellHeight(ACol, ARow: Integer): Integer; function GetCellHeight(ACol, ARow: Integer): Integer;
@ -3372,6 +3373,7 @@ var
cell: PCell; cell: PCell;
msg: String; msg: String;
begin begin
{
if (not EditorShowing) and FEditing then if (not EditorShowing) and FEditing then
begin begin
if not ValidFormula(FEditText, msg) then if not ValidFormula(FEditText, msg) then
@ -3396,6 +3398,32 @@ begin
end; end;
FEditing := false; FEditing := false;
FEnhEditMode := 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; end;
function TsCustomWorksheetGrid.EditorByStyle(Style: TColumnButtonStyle): TWinControl; function TsCustomWorksheetGrid.EditorByStyle(Style: TColumnButtonStyle): TWinControl;
@ -5395,7 +5423,6 @@ var
err: String; err: String;
begin begin
// Checking validity of formula in current cell // Checking validity of formula in current cell
if Assigned(Worksheet) and EditorMode then begin if Assigned(Worksheet) and EditorMode then begin
if not ValidFormula(FEditText, err) then begin if not ValidFormula(FEditText, err) then begin
FGridState := gsNormal; FGridState := gsNormal;
@ -5405,7 +5432,6 @@ begin
end; end;
end; end;
Result := inherited; Result := inherited;
if Result and Assigned(Worksheet) and Worksheet.IsProtected then if Result and Assigned(Worksheet) and Worksheet.IsProtected then