Author: Jonas Bilinkevicius
I am trying to make it possible for my program to create new MenuItems at runtime.
I want to copy the settings from a MenuItem made at designtime to the new
MenuItems. All the properties and event handlers.
Answer:
1 2 procedure CopyMenuRaw(const Source, MenuTest: TMenuItem);
3 begin4 MenuTest.Caption := Source.Caption;
5 MenuTest.Checked := Source.Checked;
6 MenuTest.default := Source.default;
7 MenuTest.Enabled := Source.Enabled;
8 MenuTest.GroupIndex := Source.GroupIndex;
9 MenuTest.HelpContext := Source.HelpContext;
10 MenuTest.Hint := Source.Hint;
11 MenuTest.ImageIndex := Source.ImageIndex;
12 MenuTest.Name := Source.Name;
13 MenuTest.RadioItem := Source.RadioItem;
14 MenuTest.Tag := Source.Tag;
15 MenuTest.Visible := Source.Visible;
16 MenuTest.OnClick := Source.OnClick;
17 MenuTest.OnDrawItem := Source.OnDrawItem;
18 MenuTest.OnMeasureItem := Source.OnMeasureItem;
19 end;
20 21 procedure CopyMenuItem(var Source, MenuTest: TMenuItem);
22 begin23 MenuTest := TMenuItem.Create(nil);
24 CopyMenuRaw(Source, MenuTest);
25 end;
26 27 //Used like this:28 29 CopyMenuItem(WholeScreen1, MenuTest);
Where WholeScreen1 is an existing TMenuItem and MenuTest is TMenuItem that is
defined in
your Var section.