From c0bed49a2ffa42def95e143ae388c32ee40b031a Mon Sep 17 00:00:00 2001 From: Ansgar Becker Date: Sat, 9 Aug 2008 08:31:04 +0000 Subject: [PATCH] Fix bug #654 "Edit -> Add primary index -> Crash" by preventing the cell from going into edit mode if there is no unique key available. --- source/childwin.pas | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/source/childwin.pas b/source/childwin.pas index 62a672a4..9a3f8bae 100644 --- a/source/childwin.pas +++ b/source/childwin.pas @@ -5574,22 +5574,16 @@ procedure TMDIChild.DataGridNewText(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex; NewText: WideString); var Row: TGridRow; - AllowEditing: Boolean; begin Row := FDataGridResult.Rows[Node.Index]; - AllowEditing := True; + // Remember new value + Row.Cells[Column].NewText := NewText; + Row.Cells[Column].Modified := True; + // Set state of row for UPDATE mode, don't touch grsInserted if Row.State = grsDefault then - AllowEditing := CheckUniqueKeyClause; - if AllowEditing then begin - // Remember new value - Row.Cells[Column].NewText := NewText; - Row.Cells[Column].Modified := True; - // Set state of row for UPDATE mode, don't touch grsInserted - if Row.State = grsDefault then - FDataGridResult.Rows[Node.Index].State := grsModified; - Mainform.actDataPost.Enabled := True; - Mainform.actDataCancelEdit.Enabled := True; - end; + FDataGridResult.Rows[Node.Index].State := grsModified; + Mainform.actDataPost.Enabled := True; + Mainform.actDataCancelEdit.Enabled := True; end; @@ -6044,8 +6038,13 @@ end; procedure TMDIChild.DataGridEditing(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex; var Allowed: Boolean); begin - // Move Esc shortcut from "Cancel row editing" to "Cancel cell editing" - Mainform.actDataCancelEdit.ShortCut := 0; + Allowed := True; + if FDataGridResult.Rows[Node.Index].State = grsDefault then + Allowed := CheckUniqueKeyClause; + if Allowed then begin + // Move Esc shortcut from "Cancel row editing" to "Cancel cell editing" + Mainform.actDataCancelEdit.ShortCut := 0; + end; end; procedure TMDIChild.DataGridEdited(Sender: TBaseVirtualTree; Node: