From: Mattia B. <mb...@ds...> - 2002-07-30 20:30:18
|
> >This works for me (added to minimal sample). > > >... EVT_MENU( $this, 124, sub { > #$mhelp->Destroy(($mhelp->GetMenuItems)[-1]); # this one works too > $mhelp->Destroy( 1 ); > } ); > > > Ah, using it inside the create menubar sub works, otherwise it doesn't because > you lose the handle on the menu. So, the answer was to copy the handle and make > it accessable from other subs. By "handle to the menu" do you mean $mhelp? You should be able to get it using $frame->GetMenuBar()->GetMenu(1); # or 0 or 2, etc It is just that I am lazy and didn't want to write that; it should work, though. > (Mattia) Can you explain why the handle (scalar) for the menu changes, but not > the handle for the menu bar? > using this code: > > my ($mbar) = &main::MyMenuBarFunc(); > print "mbar:$mbar\n"; > my ($mfile) = $mbar->GetMenu(0); > print "mfile:$mfile\n"; > > The latter changes later on, although mbar is the same. I think that the fact that $mbar stays the same is just the fact that the internally the same memory got reused. Basically: 1) &main::MyMenuBarFunc() allocates a scalar and returns it 2) the sacalar is freed 3) &main::MyMenuBarFunc() allocates a scalar and returns it, "casually" the scalar has the same address as the first one ("casually" means that with some changes to the code this might not be true anymore) I am not sure of that; just guessing. Regards Mattia |