Skip to content
GitLab
  • Menu
Projects Groups Snippets
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
    • Switch to GitLab Next
  • Sign in / Register
  • Lazarus Lazarus
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 2,095
    • Issues 2,095
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 7
    • Merge requests 7
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • Value stream
    • Code review
    • Insights
    • Issue
    • Repository
  • External wiki
    • External wiki
  • Activity
  • Graph
  • Create a new issue
  • Commits
  • Issue Boards
Collapse sidebar
  • FPC
  • Lazarus
  • LazarusLazarus
  • Issues
  • #30806
Closed
Open
Created Oct 27, 2016 by FPC Admin account@fpc_adminOwner

Setting Form.Menu to nil does not remove the menu

Original Reporter info from Mantis: wp @wpam
  • Reporter name:

Description:

If a form has a MainMenu it looks as if it cannot be removed any more. Setting the Menu property of the form to nil does not remove the menu. Only resizing the form does finally remove the menu. There is no response if an item of this "falsely" displayed menu is clicked.

This is in contrast do Delphi where a previously assigned menu disappears immediately after Form.Menu is set to nil.

It happens only on Windows. Linux qt and gtk2 are ok.

Steps to reproduce:

Run attached project. The Button "Toggle menu" sets the form's Menu to nil or MainMenu1. The first click sets it to nil. Therefore, it is expected that the menu of the form should disappear - it does not. In this state, change the size of the window - the menu finally disappears.

Additional information:

This is the code of TCustomForm.SetMenu (in customform.inc):

procedure TCustomForm.SetMenu(Value: TMainMenu);
var
  I: Integer;
begin
  if FMenu = Value then Exit;

  // check duplicate menus
  if Value <> nil then
    for I := 0 to Screen.FormCount - 1 do
      if (Screen.Forms[I].Menu = Value) and (Screen.Forms[I] <> Self) then
        raise EInvalidOperation.CreateFmt(sDuplicateMenus, [Value.Name]);

  if FMenu <> nil then FMenu.Parent := nil;

  if (csDestroying in ComponentState) or
     ((Value <> nil) and (csDestroying in Value.ComponentState)) then
    Value := nil;

  FMenu := Value;
  if FMenu <> nil then 
  begin
    FMenu.FreeNotification(Self);
    FMenu.Parent := Self;
    UpdateMenu;
  end;    // <-- else branch missing!
end;

The problem is that some kind of action should occur after FMenu has been set to Value (which is nil). There is some action only if FMenu is not nil.

For testing, I already added an "else" branch with "Invalidate" or "Resize" - no effect. Only having here "Height := Height-1; Height := Height+1" does remove the menu. Of course, this is not the real solution...

Mantis conversion info:

  • Mantis ID: 30806
  • OS: Win
  • OS Build: Win10
  • Platform: x86
  • Version: 1.7 (SVN)
  • Fixed in revision: 53250 (#4161b1f5)
Assignee
Assign to
Time tracking