Skip to content
Permalink
Browse files

Issue #935: cancel editing in grids other than query result grids, wh…

…en main page control tab changes. Fixes crash when changing tab while editing a column via table editor.
  • Loading branch information
ansgarbecker committed Mar 26, 2020
1 parent 9584479 commit 08597e18a818b7b4f335a046f99ba38f450fba79
Showing with 11 additions and 5 deletions.
  1. +5 −0 source/grideditlinks.pas
  2. +6 −5 source/main.pas
@@ -51,6 +51,7 @@ TBaseGridEditorLink = class(TInterfacedObject, IVTEditLink)
// 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 @@ TDataTypeEditorLink = class(TBaseGridEditorLink)
end;


var
ActiveGridEditor: TBaseGridEditorLink;

implementation

@@ -249,6 +252,7 @@ constructor TBaseGridEditorLink.Create(Tree: TVirtualStringTree; AllowEdit: Bool
SendMessage(FParentForm.Handle, WM_SETREDRAW, 0, 0);
FModified := False;
FAllowEdit := AllowEdit;
ActiveGridEditor := Self;
end;

destructor TBaseGridEditorLink.Destroy;
@@ -258,6 +262,7 @@ destructor TBaseGridEditorLink.Destroy;
DoPrev: Boolean;
begin
inherited;
ActiveGridEditor := nil;
if FLastKeyDown = VK_TAB then begin
DoPrev := ssShift in FLastShiftState;
// Advance to next/previous visible column/node.
@@ -5618,13 +5618,14 @@ procedure TMainForm.PageControlMainChange(Sender: TObject);


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;


0 comments on commit 08597e1

Please sign in to comment.
You can’t perform that action at this time.