• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 143
  • Last Modified:

easy

how to get acces on a run time created object event (with the 'create' procedure)?
for an example, the TmenuItem component

var item:TMenuItem;
begin
item:=TmenuItem.create(nil);
item.caption='test';
form1.new1.add(item);

new1 is a menuitem created at design time, and i want to get the testclick event.

thanks!
0
ralph78
Asked:
ralph78
  • 2
1 Solution
 
intheCommented:
just set the OnClick property of Item to a TNotifyEvent. For instance:
{public}
Procedure TMyForm.ClickItem(Sender:TObject);

....
implementation


//event handler
 
Procedure TMyForm.ClickItem(Sender:TObject);
begin
showmessage('menu item clicked');
end;


var item:TMenuItem;
begin
item:=TmenuItem.create(nil);
item.caption='test';
Item.OnClick := ClickItem;
form1.new1.add(item);

 
Regards Barry

 
0
 
intheCommented:
whoops typo should read:

{public}
Procedure ClickItem(Sender:TObject);

0
 
rwilson032697Commented:
If I understand you, you want to get the OnClick event for the TMenuItem you just created (and called 'test'), through the New1 menu item?

If so, you can do it like this:

for I := 0 to form1.new1.count - 1 do
  if form1.new1.items[i].Caption = 'test' then
    form1.new1.items[i].OnClick := DoTheClick;

Cheers,

Raymond.
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

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