title: Logging MenuItem OnClick Event
body: <p>I have a project (Delphi 10 Seattle, win32) with a many menus and many items in those menus. Some of the menu items are created at design time, some of them at run time. </p>
  
  <p>What I'm looking to do is log some information about the TMenuItem, such as the name/caption, timestamp, etc. when the OnClick event is triggered.</p>
  
  <p>I could simply add a procedure call to the start of every function which is assigned to the TMenuItem OnClick event but I was wondering if there was a more elegant solution.</p>
  
  <p>Also to note, I have tried <a href="https://www.embarcadero.com/products/appanalytics" rel="nofollow">Embarcadero's AppAnalytics</a> but I found it didn't give me the information or flexibility I wanted and was rather pricey.</p>
  
  <p><strong>Edit:</strong> I'll add some more information detailing what options I have considered (which I probably should've done to start with).</p>
  
  <p>The simple adding a function to every menuitem click I want to log, which would mean doing this for a lot of functions and would have to add it to every new menu item added.</p>
  
  <pre><code>procedure TSomeForm.SomeMenuItem1Click(Sender: TObject);
  var
      item : TMenuItem;
  begin
      item := Sender as TMenuItem;
      LogMenuItem(item);  // Simple log function added to the start of each menuitem click
  end;
  </code></pre>
  
  <p>By 'more elegant solution' I mean would it be possible to add a 'hook' so that all TMenuItem OnClick events triggered another procedure (which would do the logging) before calling the procedure assigned to the OnClick Event. </p>
  
  <p>Or another option I considered was creating a class which inherited from TMenuItem which would override TMenuItem.Click and do the logging before generating the OnClick event. But then I didn't know how that would work for the design time menu items without a lot of work remaking the menus.   </p>