Tuesday, December 27, 2022

Belated discovery about menu short cuts (Things I never knew about delphi, part 2)

In my blogs database program, I added at the beginning of the month some functionality to the 'show entries' form, to remove (i.e. stop displaying) an entry and to show the tags connected to an entry; these were implemented by means of a popup menu, something that I've done many times before.

Over the past few weeks, whilst entering old blogs from 2012/3, I realised that using this functionality requires two clicks (one right click to bring up the menu, one left click to choose the option). I wondered whether I could achieve the same result with one key press. In the 'manager' program, there's some arcane code using accelerator tables, used probably because I wanted this code to be in an ancestor form, from which other forms inherit these definitions. I tried to copy what I did then but couldn't get the code to work.

Then I googled 'delphi accelerator' and discovered that there was a simple solution under my fingertips. All I had to do was set the 'short cut' property of the menu item (i.e. mnRemove, mnShowtags) to a key such as F8 or F9. Once I did this, not only did this key name attach itself to the menu caption, but pressing it activated the menu option.

I might have known this once but if so, I must have forgotten years ago. Another belated discovery.



This day in history:

Blog #DateTitleTags
22227/12/2009Dollhouse 2TV series, Olivia Williams, Dollhouse
66327/12/2013Song festival - the producer speaksMIDI, Kibbutz, Song writing
78927/12/2014Sebaceous cyst and other health issuesHealth
99627/12/2016PuzzlePuzzles

No comments: