fpspreadsheet: Fix broken transfer of TsCellEdit content to the grid by clicking on the grid.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@6540 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2018-06-26 20:39:34 +00:00
parent 53e91906b0
commit d9488921a0

View File

@ -262,6 +262,7 @@ type
procedure KeyUp(var Key: Word; Shift: TShiftState); override;
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
procedure ShowCell(ACell: PCell); virtual;
procedure WriteToCell;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
@ -1953,12 +1954,13 @@ var
err: String;
begin
Result := ValidFormula(AText, err);
if not Result then begin
Worksheet.SelectCell(FRefocusingRow, FRefocusingCol);
Text := AText; // restore orig text lost by interaction with grid
SelStart := FRefocusingSelStart;
Worksheet.SelectCell(FRefocusingRow, FRefocusingCol);
Text := AText; // restore orig text lost by interaction with grid
SelStart := FRefocusingSelStart;
if Result then
WriteToCell
else
MessageDlg(err, mtError, [mbOK], 0);
end;
end;
{@@ ----------------------------------------------------------------------------
@ -1970,7 +1972,6 @@ end;
procedure TsCellEdit.EditingDone;
var
s: String;
cell: PCell;
begin
if (Worksheet = nil) then
exit;
@ -1980,14 +1981,7 @@ begin
exit;
end;
cell := Worksheet.GetCell(Worksheet.ActiveCellRow, Worksheet.ActiveCellCol);
if Worksheet.IsMerged(cell) then
cell := Worksheet.FindMergeBase(cell);
s := Lines.Text;
if (s <> '') and (s[1] = '=') then
Worksheet.WriteFormula(cell, Copy(s, 2, Length(s)), true)
else
Worksheet.WriteCellValueAsString(cell, s);
WriteToCell;
end;
{@@ ----------------------------------------------------------------------------
@ -2239,6 +2233,25 @@ begin
// here.
end;
{@@ ----------------------------------------------------------------------------
Writes the current edit text to the cell
Note: All validation checks already have been performed.
-------------------------------------------------------------------------------}
procedure TsCellEdit.WriteToCell;
var
cell: PCell;
s: String;
begin
cell := Worksheet.GetCell(Worksheet.ActiveCellRow, Worksheet.ActiveCellCol);
if Worksheet.IsMerged(cell) then
cell := Worksheet.FindMergeBase(cell);
s := Lines.Text;
if (s <> '') and (s[1] = '=') then
Worksheet.WriteFormula(cell, Copy(s, 2, Length(s)), true)
else
Worksheet.WriteCellValueAsString(cell, s);
end;
{------------------------------------------------------------------------------}
{ TsCellIndicator }