Simplify more code using the new PopupComponent() function

This commit is contained in:
Ansgar Becker
2021-01-16 18:36:01 +01:00
parent b6c9cc1e02
commit 1a7cc67e37
2 changed files with 7 additions and 10 deletions

View File

@ -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')+' (*.*)|*.*';

View File

@ -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;