Solved

TMenuItem ( onclick )

Posted on 1998-12-03
8
943 Views
Last Modified: 2006-11-17
Hello Experts...

Here is my question...
------------------------------------------------------------
How can i make a TMenuItem And Assign Any Text To The Caption in for loop and execute any of the text with form1.caption on onclick event for the TMenuItem or Popupmenu -- lets say i click on the right mouse button and after that the menu will popup and when i click any of the item then i will show the caption of the item in form1.caption...Dem this is difficult for me.. thanks!!!
0
Comment
Question by:mummi
  • 2
  • 2
  • 2
  • +1
8 Comments
 
LVL 8

Expert Comment

by:ZifNab
ID: 1349191
Hi mummi,

this should it be :

assign the onclick events of the menuitems to the menuclick event :

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    PopupMenu1: TPopupMenu;
    TEST11: TMenuItem;
    TEST21: TMenuItem;
    TEST31: TMenuItem;
    procedure MenuClick(Sender: TObject);    
  private
    { Private declarations }

  public
    { Public declarations }

  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.MenuClick(Sender: TObject);
begin
 Form1.Caption := (Sender as TMenuItem).Caption;
end;

end.

Regards, Zif.
0
 

Author Comment

by:mummi
ID: 1349192
I want to use the OnClick event on each item in the popupmenu
The menu have 3 items and let's say i will push on the third item text there is Paintbrush
and when i click the item i will execute the PaintBrush.... I 'am not building menu from popupmenu editor , i will do it by my self....

Can i use OnChange Event for the popupmenu or OnClick or ?
I'm stop

I hope you will
understand this?
Thanks!!!!!!
0
 
LVL 4

Expert Comment

by:BoRiS
ID: 1349193
mummi

try this

procedure TForm1.MyPopupHandler(Sender: TObject);
begin
  with Sender as TMenuItem do begin
    ShellExecute(Handle, 'open', Caption, '' ,'directory here', 0);
     Form1.Caption := Caption;
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
var
  i: Integer;
 MyPopUpItems: array[0..3] of TMenuItem;
begin
  for i := 0 to 3 do begin
    MyPopUpItems[i] := TMenuItem.Create(Self);
    MyPopUpItems[i].Caption := 'New item ' + IntToStr(i);
    MyPopUpMenu.Items.Add(MyPopUpItems[i]);
    MyPopUpItems[i].OnClick := MyPopupHandler;
  end;
end;

Later
BoRiS
0
 
LVL 3

Accepted Solution

by:
Ronald Buster earned 100 total points
ID: 1349194
Hi Mummi,

I think this is just what you want enjoy.

regards,

Cono

<---->

declare into TForm1 protected section

  procedure PopupHandler(Sender: TObject);

declare into TForm1 private section

  fPopUpMenu : TPopUpMenu;
  procedure InitPopUpMenu;

procedure TForm1.InitPopUpMenu;
var TM : TMenuItem;
    Ts : String;
    i  : Integer;
begin
  fPopUpMenu := TPopUpMenu.Create(Self);
  for i := 1 to 5 do
    begin
      TM         := TMenuItem.Create(Self);
      TM.Caption := 'Item ' + IntToStr(i);
      TM.Tag     := SED_CONST_QFP+(i-1);
      TM.OnClick := PopupHandler;
      fPopUpMenu.Items.Add(TM);
    end;
end;

procedure TForm1.PopupHandler(Sender: TObject);
begin
  with Sender as TMenuItem do
    begin
        Form1.Caption := Caption;
    end;
end;

procedure TForm1.Create(Sender : TObject);
begin
   PopUpMenu := fPopUpMenu;
end;

<---->
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 3

Expert Comment

by:Ronald Buster
ID: 1349195
Hi Mummi,

I forgot something

in the form create procedure

you have to call initpopupmenu, before assigning fPopupmenu to the forms popupmenu

regards,

Cono

0
 
LVL 4

Expert Comment

by:BoRiS
ID: 1349196
cono

Hmmm looks like what I said in my comment :-) non the less

Later
BoRiS
0
 

Author Comment

by:mummi
ID: 1349197
Adjusted points to 100
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1349198
like I said in my comment :

assign the onclick events of the menuitems to the menuclick event.

i.e. all menu items when clicked use menuclick procedure.

And everything should work...

In fact it's the same as cono's answer (only cono wrote it all in code ie. creation of menu) ... but heck...

Zif.

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now