Solved

adding event handler to dynamicaly created MenuItem

Posted on 1997-07-27
1
448 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
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
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…

744 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