最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

windows - Why does pressing S toggle between menu items rather than flip between multiple menu options? - Stack Overflow

programmeradmin5浏览0评论

I have a CRME of a Delphi application with the following menu (i've reproduced this in both Delphi XE6 and Delphi 7):

If you press N, it will run handler for N̲ew.

If you press O, it will run handler for O̲pen.

If you press P, it will the handler for Op̲en Recent.

If you press S, it will highlight S̲ave, but it will not run it:

And if you press S again, it will highlight Save & Minimiz̲e, but it will not run it:

And in order to try to diagnose the problem, i trimmed it down to only the menu items that start with S:

Why is this flipping happening?

Why does it only flip between those two, and not include the middle one that also starts with S?

Why does it flip between them at all?

Why does pressing O not flip between:

  • O̲pen
  • Op̲en Recent

Even removing the Ctrl+S shortcut on S̲ave doesn't fix it:

And why does it skip the middle one?

What am i missing?

CRME

FMain.pas

unit FMain;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Menus, ActnList;

type
  TForm1 = class(TForm)
     ActionList1: TActionList;
    actSave: TAction;
    actSaveAs: TAction;
    actSaveAndMinimize: TAction;
    MainMenu1: TMainMenu;
    File1: TMenuItem;
    Save1: TMenuItem;
    SaveAs1: TMenuItem;
    SaveMinimize1: TMenuItem;
    procedure actSaveExecute(Sender: TObject);
    procedure actSaveAsExecute(Sender: TObject);
    procedure actSaveAndMinimizeExecute(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.actSaveExecute(Sender: TObject);
begin
    ShowMessage('save');
end;

procedure TForm1.actSaveAsExecute(Sender: TObject);
begin
    ShowMessage('saveas');
end;

procedure TForm1.actSaveAndMinimizeExecute(Sender: TObject);
begin
    ShowMessage('save and minimize');
end;

end.

FMain.dfm

object Form1: TForm1
  Left = 448
  Top = 220
  Width = 504
  Height = 281
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  Menu = MainMenu1
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object ActionList1: TActionList
    Left = 48
    Top = 40
    object actSave: TAction
      Category = 'File'
      Caption = '&Save'
      OnExecute = actSaveExecute
    end
    object actSaveAs: TAction
      Category = 'File'
      Caption = 'Save &as'
      OnExecute = actSaveAsExecute
    end
    object actSaveAndMinimize: TAction
      Category = 'File'
      Caption = '&Save && Minimi&ze'
      OnExecute = actSaveAndMinimizeExecute
    end
  end
  object MainMenu1: TMainMenu
    Left = 16
    Top = 40
    object File1: TMenuItem
      Caption = '&File'
      object Save1: TMenuItem
        Action = actSave
      end
      object SaveAs1: TMenuItem
        Action = actSaveAs
      end
      object SaveMinimize1: TMenuItem
        Action = actSaveAndMinimize
      end
    end
  end
end

I have a CRME of a Delphi application with the following menu (i've reproduced this in both Delphi XE6 and Delphi 7):

If you press N, it will run handler for N̲ew.

If you press O, it will run handler for O̲pen.

If you press P, it will the handler for Op̲en Recent.

If you press S, it will highlight S̲ave, but it will not run it:

And if you press S again, it will highlight Save & Minimiz̲e, but it will not run it:

And in order to try to diagnose the problem, i trimmed it down to only the menu items that start with S:

Why is this flipping happening?

Why does it only flip between those two, and not include the middle one that also starts with S?

Why does it flip between them at all?

Why does pressing O not flip between:

  • O̲pen
  • Op̲en Recent

Even removing the Ctrl+S shortcut on S̲ave doesn't fix it:

And why does it skip the middle one?

What am i missing?

CRME

FMain.pas

unit FMain;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Menus, ActnList;

type
  TForm1 = class(TForm)
     ActionList1: TActionList;
    actSave: TAction;
    actSaveAs: TAction;
    actSaveAndMinimize: TAction;
    MainMenu1: TMainMenu;
    File1: TMenuItem;
    Save1: TMenuItem;
    SaveAs1: TMenuItem;
    SaveMinimize1: TMenuItem;
    procedure actSaveExecute(Sender: TObject);
    procedure actSaveAsExecute(Sender: TObject);
    procedure actSaveAndMinimizeExecute(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.actSaveExecute(Sender: TObject);
begin
    ShowMessage('save');
end;

procedure TForm1.actSaveAsExecute(Sender: TObject);
begin
    ShowMessage('saveas');
end;

procedure TForm1.actSaveAndMinimizeExecute(Sender: TObject);
begin
    ShowMessage('save and minimize');
end;

end.

FMain.dfm

object Form1: TForm1
  Left = 448
  Top = 220
  Width = 504
  Height = 281
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  Menu = MainMenu1
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object ActionList1: TActionList
    Left = 48
    Top = 40
    object actSave: TAction
      Category = 'File'
      Caption = '&Save'
      OnExecute = actSaveExecute
    end
    object actSaveAs: TAction
      Category = 'File'
      Caption = 'Save &as'
      OnExecute = actSaveAsExecute
    end
    object actSaveAndMinimize: TAction
      Category = 'File'
      Caption = '&Save && Minimi&ze'
      OnExecute = actSaveAndMinimizeExecute
    end
  end
  object MainMenu1: TMainMenu
    Left = 16
    Top = 40
    object File1: TMenuItem
      Caption = '&File'
      object Save1: TMenuItem
        Action = actSave
      end
      object SaveAs1: TMenuItem
        Action = actSaveAs
      end
      object SaveMinimize1: TMenuItem
        Action = actSaveAndMinimize
      end
    end
  end
end
Share Improve this question asked Mar 16 at 19:05 Ian BoydIan Boyd 258k269 gold badges912 silver badges1.3k bronze badges
Add a comment  | 

1 Answer 1

Reset to default 11

It's a trivial typo on your side.

The caption of actSaveAndMinimize is &Save && Minimi&ze which is invalid, since it has two accelerator characters. You clearly mean Save && Minimi&ze.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论