Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 785673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T20:55:03+00:00 2026-05-14T20:55:03+00:00

i have a method: procedure Frob(Sender: TObject); that i want to call when i

  • 0

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

  • Why doesn’t it work?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T20:55:03+00:00Added an answer on May 14, 2026 at 8:55 pm

    Have whatever object you’re in hold the animal in a private field, then set up a method that calls it. Like so:

    procedure TMyClass.AnimalFrob(Sender: TObject);
    begin
       FAnimal.Frob(sender);
    end;
    

    Then the solution becomes easy:

    menuItem.OnClick := self.AnimalFrob;

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a stored procedure that I call upon using 'core_read' and query method.
I have a method that starts my game (startGame). I call it in viewDidLoad
I have a method that calls an oracle procedure at the same time as
I have a method that calls a stored procedure. It uses the employee number
I have created a method that can be called using a stored procedure name
I have a method that calls stored procedure and returns the data after executing
I have a method set that uses pinvoke to call WM_GETTEXT on another program's
I have method in a class that I need to make sure is only
I've got some 3rd party beans that have method signatures that fit quite well
I have a method where I want to factor out some code into its

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.