Issue #935: cancel editing in grids other than query result grids, when main page control tab changes. Fixes crash when changing tab while editing a column via table editor.

This commit is contained in:
Ansgar Becker
2020-03-26 11:33:06 +01:00
parent 9584479598
commit 08597e18a8
2 changed files with 11 additions and 5 deletions

View File

@ -51,6 +51,7 @@ type
// The right constructor, we need the Tree reference
constructor Create(Tree: TVirtualStringTree; AllowEdit: Boolean); overload; virtual;
destructor Destroy; override;
property Tree: TVirtualStringTree read FTree;
function PrepareEdit(Tree: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex): Boolean; virtual; stdcall;
function BeginEdit: Boolean; virtual; stdcall;
function CancelEdit: Boolean; virtual; stdcall;
@ -213,6 +214,8 @@ type
end;
var
ActiveGridEditor: TBaseGridEditorLink;
implementation
@ -249,6 +252,7 @@ begin
SendMessage(FParentForm.Handle, WM_SETREDRAW, 0, 0);
FModified := False;
FAllowEdit := AllowEdit;
ActiveGridEditor := Self;
end;
destructor TBaseGridEditorLink.Destroy;
@ -258,6 +262,7 @@ var
DoPrev: Boolean;
begin
inherited;
ActiveGridEditor := nil;
if FLastKeyDown = VK_TAB then begin
DoPrev := ssShift in FLastShiftState;
// Advance to next/previous visible column/node.

View File

@ -5618,13 +5618,14 @@ end;
procedure TMainForm.PageControlMainChanging(Sender: TObject; var AllowChange: Boolean);
var
Grid: TVirtualStringTree;
begin
// Leave editing mode on tab changes so the editor does not stay somewhere
Grid := ActiveGrid;
if Assigned(Grid) and Grid.IsEditing then
Grid.CancelEditNode;
if Assigned(ActiveGridEditor)
and Assigned(ActiveGridEditor.Tree)
and ActiveGridEditor.Tree.IsEditing then begin
LogSQL('Cancelling tree edit mode on '+ActiveGridEditor.Tree.Name, lcDebug);
ActiveGridEditor.Tree.CancelEditNode;
end;
end;