[lazarus] LCL: menu creation order
Micha Nelissen
mdvpost at hotmail.com
Tue Jul 1 06:03:04 EDT 2003
Mattias Gaertner wrote:
> On Tue, 1 Jul 2003 10:08:38 +0200
> "Micha Nelissen" <mdvpost at hotmail.com> wrote:
>
>>
>> It first creates the children, then attaches to parent. Wouldn't it
>> be more logical to do it the other way around?
>
> Bottom-Up or Top-Down are both logical and should be supported by the
> interfaces. But for readability and debugging I changed it.
Seems reasonable.
>
>> First check/attach parent, then create children? I am asking this
>> because win32object.attachmenu uses the parent of the parent and I
>> am not sure whether it is initialized at all times, ie. the children
>> are attached to parents.
>
> What do you need to fix that?
I am wondering about the following piece of code from
win32object.attachmenu:
---
{Following part fixes the case when an item is added in runtime
but the parent item has not defined the submenu flag (hSubmenu=0) }
if (Sender as TMenuItem).Parent.Parent<>nil then
begin
ParentOfParent := (Sender as TMenuItem).Parent.Parent.Handle;
with MenuInfo do begin
cbSize:=sizeof(MENUITEMINFO);
fMask:=MIIM_SUBMENU;
end;
GetMenuItemInfo(ParentOfParent, (Sender as TMenuItem).Command,
false, @MenuInfo);
if MenuInfo.hSubmenu=0 then // the parent menu item is not yet defined
with submenu flag
begin
MenuInfo.hSubmenu:=ParentMenuHandle;
SetMenuItemInfo(ParentOfParent, (Sender as TMenuItem).Command,
false, MenuInfo);
end;
end;
---
It says it fixes something. But:
1) It it retrieves menuitem if parentofparent, it should use it's parent
command: (Sender as TMenuItem).Parent.Command.
2) All calls to InsertMenuItem (there is only 1) define menuinfo.hSubMenu :=
MenuHandle, which is always already created in CreateHandle. If I 'fix' item
1, it never gets to SetMenuItemInfo anymore, supporting this statement.
Any thoughts?
Micha.
More information about the Lazarus
mailing list