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!
ralph78Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.