Solved

adding event handler to dynamicaly created MenuItem

Posted on 1997-07-27
1
454 Views
Last Modified: 2010-04-04
Hi,
I am creating MenuItem objects (in delphi 2) dynamicaly in my program. This menu items are subItem of a static menuItem in a mainMenuItem.

The problem is thet i can't find a way to discover which of the dynamically created menu items where selected.
I can't catch the OnClick event...
I did tryied something like thet :
FOnDone: TNotifyEvent; (in TYPE)

property OnDone: TNotifyEvent read FOnDone write FOnDone; (in publish)

but i cant find the place for testing FOnDone value, or creating other function ...

HELPPPPPPPPPPPPPPPP...
0
Comment
Question by:gur
1 Comment
 
LVL 4

Accepted Solution

by:
erajoj earned 90 total points
ID: 1340062
Just do like this:

procedure TMainForm.MenuClick(Sender: TObject);
begin
  Caption := 'Menu Clicked';
end;
  ...
  ...
var
  NewMenuItem : TMenuItem;
  ...
  ...
  NewMenuItem := TMenuItem.Create(MyMenu);
  with NewMenuItem do begin
    NewMenuItem.Caption := 'EventConnected menu item';
    NewMenuItem.OnClick := MenuClick; // Here's the "magic"!
    MyMenu.Add(NewMenuItem);          // Put it last
  end;
  ...
  ...

Easier than you thought, huh?

/// John

0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to fill array with TArray.Create? 14 90
Internet Explorer View Settings Question 15 111
how can i search if string exist in array ? 3 59
Firemonkey webbrowser scrollbars ? 1 41
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

809 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