The purpose for using the main menu item's OnClick
handler is usually to determine whether sub-menu items are enabled/disabled or visible. It's also usually where you enable/disable things like toolbar buttons that perform the same function:
procedure TForm1.MyMainMenuItemClick(Sender: TObject);
begin
SomeMenuItem.Enabled := SomeConditionTest;
SomeToolButton.Enabled := SomeMenuItem.Enabled;
AnotherMenuItem.Enabled := AnotherConditionTest;
AnotherToolButton.Enabled := AnotherMenuItem.Enabled;
end;
For TActionMainMenuBar
items, you do this in the individual actions instead, in the OnUpdate
event. The advantage of this is that when you enable/disable the action, all controls connected to the action are also enabled/disabled at the same time.
procedure TForm1.SomeActionUpdate(Sender: TObject);
begin
SomeAction.Enabled := SomeConditionTest; // Also controls the toolbutton
end;
procedure TForm1.AnotherActionUpdate(Sender: TObject);
begin
AnotherAction.Enabled := AnotherConditionTest; // Toolbutton too.
end;
The OnUpdate
event is called just before the the child items are displayed, which is the same time that the old main menu item's OnClick
would be called.