Skip to content

Commit

Permalink
Refactor: merge both overloaded TQueryTabList.TabByControl methods in…
Browse files Browse the repository at this point in the history
…to a generic one, which accepts any TWinControl descendant
  • Loading branch information
ansgarbecker committed Jun 4, 2021
1 parent 87db1a1 commit bf31dfc
Showing 1 changed file with 9 additions and 20 deletions.
29 changes: 9 additions & 20 deletions source/main.pas
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,7 @@ TQueryTabList = class(TObjectList<TQueryTab>)
function ActiveMemo: TSynMemo;
function ActiveHelpersTree: TVirtualStringTree;
function TabByNumber(Number: Integer): TQueryTab;
function TabByControl(HelpersTree: TBaseVirtualTree): TQueryTab; overload;
function TabByControl(Memo: TSynMemo): TQueryTab; overload;
function TabByControl(Control: TWinControl): TQueryTab;
end;

TQueryHistoryItem = class(TObject)
Expand Down Expand Up @@ -14293,29 +14292,19 @@ function TQueryTabList.TabByNumber(Number: Integer): TQueryTab;
end;


function TQueryTabList.TabByControl(HelpersTree: TBaseVirtualTree): TQueryTab;
function TQueryTabList.TabByControl(Control: TWinControl): TQueryTab;
var
Tab: TQueryTab;
begin
// Find query tab where passed treeHelpers resides
// Find query tab where passed control resides
// Supports only most important controls in the upper area, excluding tab close button and result grid
Result := nil;
for Tab in Self do begin
if Tab.treeHelpers = HelpersTree then begin
Result := Tab;
Break;
end;
end;
end;


function TQueryTabList.TabByControl(Memo: TSynMemo): TQueryTab;
var
Tab: TQueryTab;
begin
// Find tab where passed memo resides
Result := nil;
for Tab in Self do begin
if Tab.Memo = Memo then begin
if (Control = Tab.TabSheet)
or (Control = Tab.pnlMemo) or (Control = Tab.Memo)
or (Control = Tab.pnlHelpers) or (Control = Tab.filterHelpers) or (Control = Tab.treeHelpers)
or (Control = Tab.tabsetQuery)
then begin
Result := Tab;
Break;
end;
Expand Down

0 comments on commit bf31dfc

Please sign in to comment.