Skip to content

Commit a6fd189

Browse files
committed
Fix F1 key press over menu item bug
Add OnHelp event handler on main form that cancels help operation that triggered the exception. Fixes #54
1 parent 633a18d commit a6fd189

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

Src/FmMain.dfm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,6 +1174,7 @@ inherited MainForm: TMainForm
11741174
end
11751175
end
11761176
object appEvents: TApplicationEvents
1177+
OnHelp = appEventsHelp
11771178
OnHint = appEventsHint
11781179
Left = 291
11791180
Top = 96

Src/FmMain.pas

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,11 @@ TMainForm = class(THelpAwareForm)
478478
procedure actViewTestUnitUpdate(Sender: TObject);
479479
/// <summary>Displays the Welcome page in the details pane.</summary>
480480
procedure actWelcomeExecute(Sender: TObject);
481+
/// <summary>Handles events triggered when help system is invoked. Prevents
482+
/// exception being raised when F1 key is pressed when a menu is dropped
483+
/// down.</summary>
484+
function appEventsHelp(Command: Word; Data: Integer;
485+
var CallHelp: Boolean): Boolean;
481486
/// <summary>Handles events triggered when a control issues a hint. The
482487
/// hint is displayed in the form's status bar.</summary>
483488
procedure appEventsHint(Sender: TObject);
@@ -1215,6 +1220,16 @@ procedure TMainForm.AfterShowForm;
12151220
fMainDisplayMgr.ShowWelcomePage;
12161221
end;
12171222

1223+
function TMainForm.appEventsHelp(Command: Word; Data: Integer;
1224+
var CallHelp: Boolean): Boolean;
1225+
begin
1226+
// Prevent Delphi Help system from interfering!
1227+
// This prevents exception being raised when F1 is pressed over menu items
1228+
// while still allowing our custom help manager to operate.
1229+
CallHelp := False;
1230+
Result := True;
1231+
end;
1232+
12181233
procedure TMainForm.appEventsHint(Sender: TObject);
12191234
begin
12201235
if Assigned(fStatusBarMgr) then

0 commit comments

Comments
 (0)