Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 464
  • Last Modified:

adding event handler to dynamicaly created MenuItem

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
gur
Asked:
gur
1 Solution
 
erajojCommented:
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now