From 1a7cc67e3775fadc4476c94f48e4eb57249c4623 Mon Sep 17 00:00:00 2001 From: Ansgar Becker Date: Sat, 16 Jan 2021 18:36:01 +0100 Subject: [PATCH] Simplify more code using the new PopupComponent() function --- source/main.pas | 15 ++++++--------- source/table_editor.pas | 2 +- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/source/main.pas b/source/main.pas index dee92ce3..19cc8f65 100644 --- a/source/main.pas +++ b/source/main.pas @@ -4704,20 +4704,17 @@ var Comp: TComponent; Memo: TSynMemo; Dialog: TSaveDialog; - Item: TMenuItem; begin // Save to textfile, from any TSynMemo (SQL log, "CREATE code" tab in editor, ...) - Item := (Sender as TAction).ActionComponent as TMenuItem; - Comp := (Item.GetParentMenu as TPopupMenu).PopupComponent; + Memo := nil; // Try to find memo from menu item's popup component, and if that fails, check ActiveControl. // See #353 - if (Comp <> nil) and (Comp is TSynMemo) then begin - Memo := Comp as TSynMemo; - end else if ActiveControl is TSynMemo then begin + Comp := PopupComponent(Sender); + if Comp is TSynMemo then + Memo := Comp as TSynMemo + else if ActiveControl is TSynMemo then Memo := ActiveControl as TSynMemo; - end else - Memo := nil; - if Memo <> nil then begin + if Assigned(Memo) then begin Dialog := TSaveDialog.Create(Self); Dialog.Options := Dialog.Options + [ofOverwritePrompt]; Dialog.Filter := _('SQL files')+' (*.sql)|*.sql|'+_('All files')+' (*.*)|*.*'; diff --git a/source/table_editor.pas b/source/table_editor.pas index c2a29e04..7ecab6dd 100644 --- a/source/table_editor.pas +++ b/source/table_editor.pas @@ -2383,7 +2383,7 @@ procedure TfrmTableEditor.popupPropertiesPopup(Sender: TObject); var Comp: TComponent; begin - Comp := (Sender as TPopupMenu).PopupComponent; + Comp := PopupComponent(Sender); if Comp = treeIndexes then begin menuRemoveProperty.Enabled := btnRemoveIndex.Enabled; menuClearProperties.Enabled := btnClearIndexes.Enabled;