Solved

TMenuItem ( onclick )

Posted on 1998-12-03
8
953 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
[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
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
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…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

717 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