Delphi: How to call a method when i click a control?
Posted
by Ian Boyd
on Stack Overflow
See other posts from Stack Overflow
or by Ian Boyd
Published on 2010-05-13T19:53:38Z
Indexed on
2010/05/14
7:44 UTC
Read the original article
Hit count: 228
i have a method:
procedure Frob(Sender: TObject);
that i want to call when i click a menu item.
The method comes to me though an interface:
animal: IAnimal;
IAnimal = interface
procedure Frob(Sender: TObject);
end;
The question revolves around what to assign to the OnClick
event handler of a menu item (i.e. control):
var
animal: IAnimal;
...
begin
...
menuItem := TMenuItem.Create(FileMenu)
menuItem.Caption := 'Click me!';
menuItem.OnClick := <-------- what to do
...
end;
The obvious choice, my first attempt, and the wrong answer is:
menuItem.OnClick := animal.Frob;
So how can i call a method when user clicks a control?
See also
© Stack Overflow or respective owner