?
Solved

Create mainmenu at runtime

Posted on 2000-05-11
3
Medium Priority
?
1,760 Views
Last Modified: 2008-03-10
Hi,
I have created a program that handles different files.
Now I want to create a "historymenu" for the most rescent used files.
My problem is how to create new menuitems in my excisting mainmenu.
Anyone any idea?

// svenj
0
Comment
Question by:svenj
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 3

Accepted Solution

by:
sburck earned 400 total points
ID: 2801007
The Delphi help includes this:  umnudmo.pas

This shows how to programatically build up a TMainMenu, adding new TMenuItems.  The main thrust is, do TMenuItems.Create, then add them to the mainmenu.

0
 
LVL 2

Expert Comment

by:freter
ID: 2801554
from my PAQ (http://www1.experts-exchange.com/bin/Q.10132229)

basically the same...

Q:
How can I create TMenuItems when the application is running?
How can I assign methods to the items created?

A:
(From: freter
 Date: Wednesday, February 24 1999 - 04:13AM PST )

Here we go:
>>>>>>>>>>>>>>>>>>>><< 
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Menus;

type
  TForm1 = class(TForm)
    MainMenu1: TMainMenu;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure ExitClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var item: TMenuItem;
    item2: tmenuitem;
begin
  item := tmenuitem.create(MainMenu1);
  item.Caption := '&File';
  MainMenu1.Items.Add(item);

  item2 := tmenuitem.create(MainMenu1);
  item2.Caption := 'E&xit';
  item2.OnClick := ExitClick;
  item.Add(item2);

end;

procedure TForm1.ExitClick(Sender: TObject);
begin
  Application.Terminate;
end;

end.
<<<<<<<<<<<<<<<<<<<< 

Don't forget to place a TMainMenu named MainMenu1 and a TButton named Button1 onto your form. Also, please take care to attach the OnClick event to the Button1Click method.

Have fun,
<freter>
0
 
LVL 3

Expert Comment

by:shenqw
ID: 2803323
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Menus, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
    MainMenu:TMainMenu;
    procedure MenuClick(Sender:TObject);
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
  MenuItem:TMenuItem;
  SubMenuItem:TMenuItem;
begin
  if MainMenu<>nil then Exit;
  MainMenu:=TMainMenu.Create(Self);
  MenuItem:=TMenuItem.Create(Self);
  MenuItem.Caption:='&File';
  SubMenuItem:=TMenuItem.Create(Self);
  SubMenuItem.Caption:='&SubFile';
  SubMenuItem.OnClick:=MenuClick;
  MenuItem.Add(SubMenuItem);
  MainMenu.Items.Add(MenuItem);
  Self.Menu:=MainMenu;
end;

procedure TForm1.MenuClick(Sender: TObject);
begin
  ShowMessage(TMenuItem(Sender).Caption);
end;

end.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses
Course of the Month12 days, 4 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question