I would actually like to copy two submenus on my TMainMenu in their
entirety into my TPopupMenu at runtime. These two submenus have Tags
= 1. But the following code produces a "Menu Inserted Twice" runtime
error:
for i := 0 to MainMenu.Items.Count - 1 do begin
if (MainMenu.Items[i].Tag = 1) then begin
MainPopupMenu.Items.Insert(0,MainMenu.Items[i]);
end;
end;
Is there anyway to accomplish this?
Thanks,
Steve
There are two loops here. The first (outer) is for the menu Titles across
the top, the second (inner) is for the SubItems under the MenuTitle. I
don't think you can add an Item straight across, but you can assign a new
item it's properties.
The only thing I'm a little unclear about is the use of the Create for the
MenuItem and Freeing it. The examples I've seen in the PAS files that were
distributed with Delphi show MenuItems being Created and never freed. I
checked my system resources after running this several times, and noticed no
apparent leakage.
Var i,ii : Integer ;
MySubItem : TMenuItem;
Begin
For i := 0 To (MainMenu1.Items.Count-1) Do Begin
// MainMenu Title Loop
If MainMenu1.Items[i].Tag = 1 Then Begin
For ii:=0 To (MainMenu1.Items.Items[i].Count-1) Do Begin
// Menu SubItems Loop
If MainMenu1.Items[i].Items[ii].Tag = 1 Then Begin
MySubItem := TMenuItem.Create(Self);
PopupMenu1.Items.Add(MySubItem);
MySubItem.Caption := MainMenu1.Items[i].Items[ii].Caption ;
MySubItem.OnClick := MainMenu1.Items[i].Items[ii].OnClick ;
End;
End;
End;
End; //For
End;
-Steve-
Stephen Smith wrote in message <34b0822b...@news.mindspring.com>...
MySubItem := TMenuItem.Create(Self);
In fact, any type of component created that way is freed in the same manner.
But if you specify "nil" for the owner, as in:
MySubItem := TMenuItem.Create(nil);
then you *would* have to manually free the item.
--
Jordan Russell
(Remove "xyz." from my address when replying to me by e-mail)
Steve Zimmelman wrote in message <68opm0$1t...@forums.borland.com>...