From 6f902032d81f498ba79044b61a199c85845301f5 Mon Sep 17 00:00:00 2001 From: DungSaga Date: Sun, 24 Apr 2022 19:24:29 +0700 Subject: [PATCH 01/15] follow foreign key to the reference table and filter to show only rows linked from the current row --- source/main.dfm | 10 +++++++++ source/main.pas | 60 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) diff --git a/source/main.dfm b/source/main.dfm index 7604805c3..4f017bc44 100644 --- a/source/main.dfm +++ b/source/main.dfm @@ -2374,6 +2374,13 @@ object MainForm: TMainForm ImageName = 'icons8-close-button' OnExecute = actExitApplicationExecute end + object actFollowForeignKey: TAction + Category = 'Various' + Caption = 'Follow Foreign Key' + Hint = 'Follow foreign key to the linked table' + ImageIndex = 61 + OnExecute = actFollowForeignKeyExecute + end object actCopy: TAction Category = 'Various' Caption = '&Copy' @@ -3785,6 +3792,9 @@ object MainForm: TMainForm OnPopup = popupDataGridPopup Left = 200 Top = 248 + object FollowForeignKey: TMenuItem + Action = actFollowForeignKey + end object Copy3: TMenuItem Action = actCopy end diff --git a/source/main.pas b/source/main.pas index 3f3cbf8e4..e4554cc5a 100644 --- a/source/main.pas +++ b/source/main.pas @@ -190,6 +190,7 @@ TMainForm = class(TExtForm) MainMenuFile: TMenuItem; FileNewItem: TMenuItem; MainMenuHelp: TMenuItem; + FollowForeignKey: TMenuItem; N1: TMenuItem; FileExitItem: TMenuItem; menuAbout: TMenuItem; @@ -198,6 +199,7 @@ TMainForm = class(TExtForm) PasteItem: TMenuItem; StatusBar: TStatusBar; ActionList1: TActionList; + actFollowForeignKey: TAction; actCopy: TAction; actPaste: TAction; actNewWindow: TAction; @@ -954,6 +956,7 @@ TMainForm = class(TExtForm) procedure ListTablesInitNode(Sender: TBaseVirtualTree; ParentNode, Node: PVirtualNode; var InitialStates: TVirtualNodeInitStates); procedure AnyGridAfterPaint(Sender: TBaseVirtualTree; TargetCanvas: TCanvas); + procedure actFollowForeignKeyExecute(Sender: TObject); procedure actCopyOrCutExecute(Sender: TObject); procedure actPasteExecute(Sender: TObject); procedure actSelectAllExecute(Sender: TObject); @@ -11252,6 +11255,63 @@ procedure TMainForm.HostListBeforeCellPaint(Sender: TBaseVirtualTree; TargetCanv end; +procedure TMainForm.actFollowForeignKeyExecute(Sender: TObject); +var + //vt: TVirtualStringTree; + CurrentControl: TWinControl; + Grid: TVirtualStringTree; + TextCopy, FocusedColumnName, ForeignColumnName, ReferenceTable: String; + HasNulls: Boolean; + ForeignKey: TForeignKey; + i: Integer; + PDBObj: PDBObject; + DBObj: TDBObject; + Node: PVirtualNode; +begin + //vt := Sender as TVirtualStringTree; + CurrentControl := Screen.ActiveControl; + Grid := CurrentControl as TVirtualStringTree; + TextCopy := Grid.Text[Grid.FocusedNode, Grid.FocusedColumn]; + //RemoveNullChars(TextCopy, HasNulls); + //get column name from header + FocusedColumnName := Grid.Header.Columns[Grid.FocusedColumn].Text; + + //find foreign key for current column + for ForeignKey in ActiveDBObj.TableForeignKeys do begin + i := ForeignKey.Columns.IndexOf(DataGrid.Header.Columns[Grid.FocusedColumn].Text); + if i > -1 then begin + ForeignColumnName := ForeignKey.ForeignColumns[i]; + ReferenceTable := ForeignKey.ReferenceTable; + break; + end; + end; + // jump to ReferenceTable + Node := GetNextNode(ListTables, nil); + while Assigned(Node) do begin + PDBObj := ListTables.GetNodeData(Node); + DBObj := PDBObj^; + if DBObj.Database + '.' + DBObj.Name = ReferenceTable then begin + // ShowStatusMsg('--' + DBObj.Database + '.' + DBObj.Name, 0); + ActiveDBObj := DBObj; + // SetMainTab(tabEditor); + break; + end; + Node := GetNextNode(ListTables, Node); + end; + + // filter to show only rows with + if ForeignColumnName.Length > 0 then begin + // Sleep(200); + SynMemoFilter.UndoList.AddGroupBreak; + // SynMemoFilter.SelectAll; + // SynMemoFilter.SelText := ForeignColumnName + ' = "' + StringReplace(TextCopy, ',', '', [rfReplaceAll]) + '"'; + SynMemoFilter.Text := ForeignColumnName + ' = "' + TextCopy + '"'; + ToggleFilterPanel(True); + actApplyFilterExecute(nil); + end; +end; + + procedure TMainForm.actCopyOrCutExecute(Sender: TObject); var CurrentControl: TWinControl; From 3c7adebe0c976a135818b3ab85428ad11ab01aa3 Mon Sep 17 00:00:00 2001 From: DungSaga Date: Mon, 25 Apr 2022 00:20:38 +0700 Subject: [PATCH 02/15] get raw data from grid (instead of displayed text) --- source/main.pas | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/source/main.pas b/source/main.pas index e4554cc5a..e03537806 100644 --- a/source/main.pas +++ b/source/main.pas @@ -11260,6 +11260,8 @@ procedure TMainForm.actFollowForeignKeyExecute(Sender: TObject); //vt: TVirtualStringTree; CurrentControl: TWinControl; Grid: TVirtualStringTree; + Results: TDBQuery; + RowNum: PInt64; TextCopy, FocusedColumnName, ForeignColumnName, ReferenceTable: String; HasNulls: Boolean; ForeignKey: TForeignKey; @@ -11271,7 +11273,10 @@ procedure TMainForm.actFollowForeignKeyExecute(Sender: TObject); //vt := Sender as TVirtualStringTree; CurrentControl := Screen.ActiveControl; Grid := CurrentControl as TVirtualStringTree; - TextCopy := Grid.Text[Grid.FocusedNode, Grid.FocusedColumn]; + Results := GridResult(Grid); + RowNum := Grid.GetNodeData(Grid.FocusedNode); + Results.RecNo := RowNum^; + TextCopy := Results.Col(Grid.FocusedColumn); //RemoveNullChars(TextCopy, HasNulls); //get column name from header FocusedColumnName := Grid.Header.Columns[Grid.FocusedColumn].Text; From 9ca9d3936cae7b935415281376c1885086f4901d Mon Sep 17 00:00:00 2001 From: DungSaga Date: Wed, 27 Apr 2022 17:06:01 +0700 Subject: [PATCH 03/15] update asFilter, because SynMemoFilter will be cleared and set value of asFilter (in HandleDataGridAttributes from DataGridBeforePaint) --- source/main.pas | 3 +++ 1 file changed, 3 insertions(+) diff --git a/source/main.pas b/source/main.pas index e03537806..75e118dfb 100644 --- a/source/main.pas +++ b/source/main.pas @@ -11314,6 +11314,9 @@ procedure TMainForm.actFollowForeignKeyExecute(Sender: TObject); ToggleFilterPanel(True); actApplyFilterExecute(nil); end; + // SynMemoFilter will be cleared and set value of asFilter (in HandleDataGridAttributes from DataGridBeforePaint) + AppSettings.SessionPath := GetRegKeyTable; + AppSettings.WriteString(asFilter, SynMemoFilter.Text); end; From e6155c367271ec3ffa2193093aacfbeeb8a5314d Mon Sep 17 00:00:00 2001 From: DungSaga Date: Wed, 27 Apr 2022 17:06:41 +0700 Subject: [PATCH 04/15] code refactor --- source/main.pas | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/source/main.pas b/source/main.pas index 75e118dfb..aa95352f3 100644 --- a/source/main.pas +++ b/source/main.pas @@ -11257,12 +11257,11 @@ procedure TMainForm.HostListBeforeCellPaint(Sender: TBaseVirtualTree; TargetCanv procedure TMainForm.actFollowForeignKeyExecute(Sender: TObject); var - //vt: TVirtualStringTree; CurrentControl: TWinControl; Grid: TVirtualStringTree; Results: TDBQuery; RowNum: PInt64; - TextCopy, FocusedColumnName, ForeignColumnName, ReferenceTable: String; + FocusedValue, FocusedColumnName, ForeignColumnName, ReferenceTable: String; HasNulls: Boolean; ForeignKey: TForeignKey; i: Integer; @@ -11270,14 +11269,12 @@ procedure TMainForm.actFollowForeignKeyExecute(Sender: TObject); DBObj: TDBObject; Node: PVirtualNode; begin - //vt := Sender as TVirtualStringTree; CurrentControl := Screen.ActiveControl; Grid := CurrentControl as TVirtualStringTree; Results := GridResult(Grid); RowNum := Grid.GetNodeData(Grid.FocusedNode); Results.RecNo := RowNum^; - TextCopy := Results.Col(Grid.FocusedColumn); - //RemoveNullChars(TextCopy, HasNulls); + FocusedValue := Results.Col(Grid.FocusedColumn); //get column name from header FocusedColumnName := Grid.Header.Columns[Grid.FocusedColumn].Text; @@ -11290,30 +11287,26 @@ procedure TMainForm.actFollowForeignKeyExecute(Sender: TObject); break; end; end; + if ForeignColumnName = '' then begin + LogSQL(f_('Foreign key not found for column "%s"', [FocusedColumnName]), lcInfo); + exit; + end; // jump to ReferenceTable Node := GetNextNode(ListTables, nil); while Assigned(Node) do begin PDBObj := ListTables.GetNodeData(Node); DBObj := PDBObj^; if DBObj.Database + '.' + DBObj.Name = ReferenceTable then begin - // ShowStatusMsg('--' + DBObj.Database + '.' + DBObj.Name, 0); ActiveDBObj := DBObj; - // SetMainTab(tabEditor); break; end; Node := GetNextNode(ListTables, Node); end; - - // filter to show only rows with - if ForeignColumnName.Length > 0 then begin - // Sleep(200); - SynMemoFilter.UndoList.AddGroupBreak; - // SynMemoFilter.SelectAll; - // SynMemoFilter.SelText := ForeignColumnName + ' = "' + StringReplace(TextCopy, ',', '', [rfReplaceAll]) + '"'; - SynMemoFilter.Text := ForeignColumnName + ' = "' + TextCopy + '"'; - ToggleFilterPanel(True); - actApplyFilterExecute(nil); - end; + // filter to show only rows linked by the foreign key + SynMemoFilter.UndoList.AddGroupBreak; + SynMemoFilter.Text := ForeignColumnName + ' = "' + FocusedValue + '"'; + ToggleFilterPanel(True); + actApplyFilter.Execute; // SynMemoFilter will be cleared and set value of asFilter (in HandleDataGridAttributes from DataGridBeforePaint) AppSettings.SessionPath := GetRegKeyTable; AppSettings.WriteString(asFilter, SynMemoFilter.Text); From 08cafee0bb4057d5f9191f26e9dec9897212ee80 Mon Sep 17 00:00:00 2001 From: DungSaga Date: Wed, 27 Apr 2022 16:59:56 +0700 Subject: [PATCH 05/15] add shortcut (Alt+Right) --- source/main.dfm | 1 + 1 file changed, 1 insertion(+) diff --git a/source/main.dfm b/source/main.dfm index 4f017bc44..dc913ba4c 100644 --- a/source/main.dfm +++ b/source/main.dfm @@ -3794,6 +3794,7 @@ object MainForm: TMainForm Top = 248 object FollowForeignKey: TMenuItem Action = actFollowForeignKey + ShortCut = 32807 end object Copy3: TMenuItem Action = actCopy From 71aeef837e072c8dbd71ab5d1a9bcd1f6d8bc10a Mon Sep 17 00:00:00 2001 From: DungSaga Date: Wed, 27 Apr 2022 18:02:47 +0700 Subject: [PATCH 06/15] add shortcut (double click) --- source/main.dfm | 1 + source/main.pas | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/source/main.dfm b/source/main.dfm index dc913ba4c..9b52dea22 100644 --- a/source/main.dfm +++ b/source/main.dfm @@ -1247,6 +1247,7 @@ object MainForm: TMainForm OnChange = AnyGridChange OnColumnResize = DataGridColumnResize OnCreateEditor = AnyGridCreateEditor + OnDblClick = AnyGridDblClick OnEditCancelled = AnyGridEditCancelled OnEdited = AnyGridEdited OnEditing = AnyGridEditing diff --git a/source/main.pas b/source/main.pas index aa95352f3..44c751e91 100644 --- a/source/main.pas +++ b/source/main.pas @@ -1170,6 +1170,7 @@ TMainForm = class(TExtForm) NewDPI: Integer); procedure menuCloseTabOnDblClickClick(Sender: TObject); procedure TimerRefreshTimer(Sender: TObject); + procedure AnyGridDblClick(Sender: TObject); private // Executable file details FAppVerMajor: Integer; @@ -10325,6 +10326,12 @@ procedure TMainForm.AnyGridChange(Sender: TBaseVirtualTree; Node: PVirtualNode); end; +procedure TMainForm.AnyGridDblClick(Sender: TObject); +begin + //if KeyPressed(VK_MENU) then // VK_MENU is Alt key + actFollowForeignKey.Execute; +end; + procedure TMainForm.AnyGridKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); var g: TVirtualStringTree; From f677de4fa4d7b63f790ff96f92fb184f14bbdd44 Mon Sep 17 00:00:00 2001 From: DungSaga Date: Wed, 27 Apr 2022 18:06:27 +0700 Subject: [PATCH 07/15] [build] ignore compile output --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 16c8d23ce..6e26b109c 100644 --- a/.gitignore +++ b/.gitignore @@ -17,4 +17,5 @@ __recovery *.mo *.po *.res -out/Backups/* \ No newline at end of file +out/Backups/* +out/* \ No newline at end of file From 5f22d636f3b2b9d0599b30f6154dcb4137d69836 Mon Sep 17 00:00:00 2001 From: DungSaga Date: Wed, 27 Apr 2022 18:34:00 +0700 Subject: [PATCH 08/15] only enable "follow foreign key" in tab "Data" --- source/main.pas | 1 + 1 file changed, 1 insertion(+) diff --git a/source/main.pas b/source/main.pas index 44c751e91..44a63db71 100644 --- a/source/main.pas +++ b/source/main.pas @@ -7704,6 +7704,7 @@ procedure TMainForm.popupDataGridPopup(Sender: TObject); menuSQLHelpData.Enabled := InDataGrid; Refresh3.Enabled := InDataGrid; actGridEditFunction.Enabled := CellFocused; + actFollowForeignKey.Enabled := InDataGrid; if not CellFocused then Exit; From b7401dd1d63f0a2ead6005fdeb8c68d122723790 Mon Sep 17 00:00:00 2001 From: DungSaga Date: Fri, 29 Apr 2022 06:19:19 +0700 Subject: [PATCH 09/15] Revert "add shortcut (Alt+Right)" This reverts commit 08cafee0bb4057d5f9191f26e9dec9897212ee80. --- source/main.dfm | 1 - 1 file changed, 1 deletion(-) diff --git a/source/main.dfm b/source/main.dfm index 9b52dea22..c849d55bf 100644 --- a/source/main.dfm +++ b/source/main.dfm @@ -3795,7 +3795,6 @@ object MainForm: TMainForm Top = 248 object FollowForeignKey: TMenuItem Action = actFollowForeignKey - ShortCut = 32807 end object Copy3: TMenuItem Action = actCopy From d6f59f1e6b8b2d7dfbb9290e8b9bce5c5fea7365 Mon Sep 17 00:00:00 2001 From: DungSaga Date: Fri, 29 Apr 2022 06:28:31 +0700 Subject: [PATCH 10/15] change shortcut to shift double click --- source/main.pas | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/main.pas b/source/main.pas index 44a63db71..77ff93a3f 100644 --- a/source/main.pas +++ b/source/main.pas @@ -10329,7 +10329,7 @@ procedure TMainForm.AnyGridChange(Sender: TBaseVirtualTree; Node: PVirtualNode); procedure TMainForm.AnyGridDblClick(Sender: TObject); begin - //if KeyPressed(VK_MENU) then // VK_MENU is Alt key + if KeyPressed(VK_SHIFT) then actFollowForeignKey.Execute; end; From e3d1156090f16128755426b6ae7bceeb89391030 Mon Sep 17 00:00:00 2001 From: DungSaga Date: Fri, 29 Apr 2022 06:59:02 +0700 Subject: [PATCH 11/15] only enable "follow foreign key" when a foreign key is found for the current column --- source/main.dfm | 1 + source/main.pas | 20 +++++++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/source/main.dfm b/source/main.dfm index c849d55bf..8b7d957f9 100644 --- a/source/main.dfm +++ b/source/main.dfm @@ -2378,6 +2378,7 @@ object MainForm: TMainForm object actFollowForeignKey: TAction Category = 'Various' Caption = 'Follow Foreign Key' + Enabled = False Hint = 'Follow foreign key to the linked table' ImageIndex = 61 OnExecute = actFollowForeignKeyExecute diff --git a/source/main.pas b/source/main.pas index 77ff93a3f..2eb394657 100644 --- a/source/main.pas +++ b/source/main.pas @@ -7679,7 +7679,7 @@ procedure TMainForm.popupDataGridPopup(Sender: TObject); Grid: TVirtualStringTree; Results: TDBQuery; i: Integer; - Col, Value: String; + Col, Value, FocusedColumnName: String; CellFocused, InDataGrid, HasNullValue, HasNotNullValue: Boolean; RowNumber: PInt64; Node: PVirtualNode; @@ -7687,6 +7687,7 @@ procedure TMainForm.popupDataGridPopup(Sender: TObject); IncludedValues: TStringList; Act: TAction; Datatype: TDBDatatype; + ForeignKey: TForeignKey; const CLPBRD : String = 'CLIPBOARD'; begin @@ -7704,7 +7705,6 @@ procedure TMainForm.popupDataGridPopup(Sender: TObject); menuSQLHelpData.Enabled := InDataGrid; Refresh3.Enabled := InDataGrid; actGridEditFunction.Enabled := CellFocused; - actFollowForeignKey.Enabled := InDataGrid; if not CellFocused then Exit; @@ -7850,6 +7850,20 @@ procedure TMainForm.popupDataGridPopup(Sender: TObject); Act.Caption := StrEllipsis(Act.Hint, 100); end; + actFollowForeignKey.Enabled := False; + if (InDataGrid) then begin + //get column name from header + FocusedColumnName := Grid.Header.Columns[Grid.FocusedColumn].Text; + + //find foreign key for current column + for ForeignKey in ActiveDBObj.TableForeignKeys do begin + i := ForeignKey.Columns.IndexOf(FocusedColumnName); + if i > -1 then begin + actFollowForeignKey.Enabled := True; + break; + end; + end; + end; end; @@ -10329,7 +10343,7 @@ procedure TMainForm.AnyGridChange(Sender: TBaseVirtualTree; Node: PVirtualNode); procedure TMainForm.AnyGridDblClick(Sender: TObject); begin - if KeyPressed(VK_SHIFT) then + if actFollowForeignKey.Enabled and KeyPressed(VK_SHIFT) then actFollowForeignKey.Execute; end; From c6c6497b076d22a2f9e9dc690f86fd5d3084f460 Mon Sep 17 00:00:00 2001 From: DungSaga Date: Fri, 29 Apr 2022 07:14:28 +0700 Subject: [PATCH 12/15] move "follow foreign key" to below menu item "Open URL" --- source/main.dfm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/main.dfm b/source/main.dfm index 8b7d957f9..cd9942c28 100644 --- a/source/main.dfm +++ b/source/main.dfm @@ -3794,9 +3794,6 @@ object MainForm: TMainForm OnPopup = popupDataGridPopup Left = 200 Top = 248 - object FollowForeignKey: TMenuItem - Action = actFollowForeignKey - end object Copy3: TMenuItem Action = actCopy end @@ -3928,6 +3925,9 @@ object MainForm: TMainForm object OpenURL1: TMenuItem Action = actDataOpenUrl end + object FollowForeignKey: TMenuItem + Action = actFollowForeignKey + end object N4a: TMenuItem Caption = '-' end From 85e86787f691bdd41688b95cd9056235bae63229 Mon Sep 17 00:00:00 2001 From: DungSaga Date: Fri, 29 Apr 2022 07:13:42 +0700 Subject: [PATCH 13/15] escape value of current column before following to foreign key --- source/main.pas | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/source/main.pas b/source/main.pas index 2eb394657..2bb70d1c4 100644 --- a/source/main.pas +++ b/source/main.pas @@ -11284,12 +11284,12 @@ procedure TMainForm.actFollowForeignKeyExecute(Sender: TObject); Results: TDBQuery; RowNum: PInt64; FocusedValue, FocusedColumnName, ForeignColumnName, ReferenceTable: String; - HasNulls: Boolean; ForeignKey: TForeignKey; i: Integer; PDBObj: PDBObject; DBObj: TDBObject; Node: PVirtualNode; + Datatype: TDBDatatype; begin CurrentControl := Screen.ActiveControl; Grid := CurrentControl as TVirtualStringTree; @@ -11302,7 +11302,7 @@ procedure TMainForm.actFollowForeignKeyExecute(Sender: TObject); //find foreign key for current column for ForeignKey in ActiveDBObj.TableForeignKeys do begin - i := ForeignKey.Columns.IndexOf(DataGrid.Header.Columns[Grid.FocusedColumn].Text); + i := ForeignKey.Columns.IndexOf(Grid.Header.Columns[Grid.FocusedColumn].Text); if i > -1 then begin ForeignColumnName := ForeignKey.ForeignColumns[i]; ReferenceTable := ForeignKey.ReferenceTable; @@ -11324,9 +11324,10 @@ procedure TMainForm.actFollowForeignKeyExecute(Sender: TObject); end; Node := GetNextNode(ListTables, Node); end; + Datatype := ActiveDBObj.TableColumns[Grid.FocusedColumn].DataType; // filter to show only rows linked by the foreign key SynMemoFilter.UndoList.AddGroupBreak; - SynMemoFilter.Text := ForeignColumnName + ' = "' + FocusedValue + '"'; + SynMemoFilter.Text := Results.Connection.QuoteIdent(ForeignColumnName, False) + '=' + Results.Connection.EscapeString(FocusedValue, Datatype); ToggleFilterPanel(True); actApplyFilter.Execute; // SynMemoFilter will be cleared and set value of asFilter (in HandleDataGridAttributes from DataGridBeforePaint) From 2877cbcdbeaf694a3f9381c581883c28e29a685f Mon Sep 17 00:00:00 2001 From: DungSaga Date: Fri, 29 Apr 2022 09:54:38 +0700 Subject: [PATCH 14/15] get column name from GridResult (instead of Grid.Header) --- source/main.pas | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/source/main.pas b/source/main.pas index 2bb70d1c4..5e0eca642 100644 --- a/source/main.pas +++ b/source/main.pas @@ -7852,9 +7852,7 @@ procedure TMainForm.popupDataGridPopup(Sender: TObject); actFollowForeignKey.Enabled := False; if (InDataGrid) then begin - //get column name from header - FocusedColumnName := Grid.Header.Columns[Grid.FocusedColumn].Text; - + FocusedColumnName := Results.ColumnOrgNames[Grid.FocusedColumn]; //find foreign key for current column for ForeignKey in ActiveDBObj.TableForeignKeys do begin i := ForeignKey.Columns.IndexOf(FocusedColumnName); @@ -11296,13 +11294,11 @@ procedure TMainForm.actFollowForeignKeyExecute(Sender: TObject); Results := GridResult(Grid); RowNum := Grid.GetNodeData(Grid.FocusedNode); Results.RecNo := RowNum^; - FocusedValue := Results.Col(Grid.FocusedColumn); - //get column name from header - FocusedColumnName := Grid.Header.Columns[Grid.FocusedColumn].Text; + FocusedColumnName := Results.ColumnOrgNames[Grid.FocusedColumn]; //find foreign key for current column for ForeignKey in ActiveDBObj.TableForeignKeys do begin - i := ForeignKey.Columns.IndexOf(Grid.Header.Columns[Grid.FocusedColumn].Text); + i := ForeignKey.Columns.IndexOf(FocusedColumnName); if i > -1 then begin ForeignColumnName := ForeignKey.ForeignColumns[i]; ReferenceTable := ForeignKey.ReferenceTable; @@ -11324,7 +11320,8 @@ procedure TMainForm.actFollowForeignKeyExecute(Sender: TObject); end; Node := GetNextNode(ListTables, Node); end; - Datatype := ActiveDBObj.TableColumns[Grid.FocusedColumn].DataType; + Datatype := Results.DataType(Grid.FocusedColumn); + FocusedValue := Results.Col(Grid.FocusedColumn); // filter to show only rows linked by the foreign key SynMemoFilter.UndoList.AddGroupBreak; SynMemoFilter.Text := Results.Connection.QuoteIdent(ForeignColumnName, False) + '=' + Results.Connection.EscapeString(FocusedValue, Datatype); From 51476b65a5a9f4a1cf8ec3d9698783a3e71b15a8 Mon Sep 17 00:00:00 2001 From: DungSaga Date: Fri, 29 Apr 2022 15:58:01 +0700 Subject: [PATCH 15/15] remove shortcut "shift double click" --- source/main.dfm | 1 - source/main.pas | 8 -------- 2 files changed, 9 deletions(-) diff --git a/source/main.dfm b/source/main.dfm index cd9942c28..4a8da3b68 100644 --- a/source/main.dfm +++ b/source/main.dfm @@ -1247,7 +1247,6 @@ object MainForm: TMainForm OnChange = AnyGridChange OnColumnResize = DataGridColumnResize OnCreateEditor = AnyGridCreateEditor - OnDblClick = AnyGridDblClick OnEditCancelled = AnyGridEditCancelled OnEdited = AnyGridEdited OnEditing = AnyGridEditing diff --git a/source/main.pas b/source/main.pas index 5e0eca642..cd416e0c9 100644 --- a/source/main.pas +++ b/source/main.pas @@ -1170,7 +1170,6 @@ TMainForm = class(TExtForm) NewDPI: Integer); procedure menuCloseTabOnDblClickClick(Sender: TObject); procedure TimerRefreshTimer(Sender: TObject); - procedure AnyGridDblClick(Sender: TObject); private // Executable file details FAppVerMajor: Integer; @@ -10338,13 +10337,6 @@ procedure TMainForm.AnyGridChange(Sender: TBaseVirtualTree; Node: PVirtualNode); UpdateLineCharPanel; end; - -procedure TMainForm.AnyGridDblClick(Sender: TObject); -begin - if actFollowForeignKey.Enabled and KeyPressed(VK_SHIFT) then - actFollowForeignKey.Execute; -end; - procedure TMainForm.AnyGridKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); var g: TVirtualStringTree;