Today I found the bug in CheckMenuDropdown method for standard TToolBar component. If you’ll assign to toolbar the mainmenu and one from item will have a lot of subitems (some are visible) then the position of dropdown menu will be incorrect (above of toolbar).
The reason of bug is the next code:
if (GetSystemMetrics(SM_CYMENU) * FTempMenu.Items.Count) + APoint.Y > Screen.MonitorFromPoint(APoint).Height then Dec(APoint.Y, Button.Height);
As you see, the FTempMenu.Items.Count will return the counf of all subitems (including hidden).
The correct code:
if (GetSystemMetrics(SM_CYMENU) * GetVisibleMenuItemCount()) + APoint.Y > Screen.MonitorFromPoint(APoint).Height then Dec(APoint.Y, Button.Height);
where GetVisibleMenuItemCount function is
function GetVisibleMenuItemCount: Integer; var i: Integer; begin Result := 0; for i := 0 to FTempMenu.Items.Count-1 do if FTempMenu.Items[i].Visible then Inc(Result) end;
Unfortunatelly there is no way to override the CheckMenuDropdown method to fix this issue because all used variables (FTempMenu, FCaptureChangeCancels etc). So only one way is to patch the ComCtrls.pas unit.
This bug confirmed in all versions from Delphi 6 to XE4.