2009. szeptember 2., szerda
How to copy all settings from a MenuItem made at designtime to a MenuItem created at runtime
Problem/Question/Abstract:
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:
procedure CopyMenuRaw(const Source, MenuTest: TMenuItem);
begin
MenuTest.Caption := Source.Caption;
MenuTest.Checked := Source.Checked;
MenuTest.Default := Source.Default;
MenuTest.Enabled := Source.Enabled;
MenuTest.GroupIndex := Source.GroupIndex;
MenuTest.HelpContext := Source.HelpContext;
MenuTest.Hint := Source.Hint;
MenuTest.ImageIndex := Source.ImageIndex;
MenuTest.Name := Source.Name;
MenuTest.RadioItem := Source.RadioItem;
MenuTest.Tag := Source.Tag;
MenuTest.Visible := Source.Visible;
MenuTest.OnClick := Source.OnClick;
MenuTest.OnDrawItem := Source.OnDrawItem;
MenuTest.OnMeasureItem := Source.OnMeasureItem;
end;
procedure CopyMenuItem(var Source, MenuTest: TMenuItem);
begin
MenuTest := TMenuItem.Create(nil);
CopyMenuRaw(Source, MenuTest);
end;
Used like this:
CopyMenuItem(WholeScreen1, MenuTest);
Where WholeScreen1 is an existing TMenuItem and MenuTest is TMenuItem that is defined in
your Var section.
Feliratkozás:
Megjegyzések küldése (Atom)
Nincsenek megjegyzések:
Megjegyzés küldése