TechTricks
Technical answers from the trenches 
 
 
 
 

     
   
Controlling Shortcut Menus
 
   
 Posted: 25 February 2003
 
   
 
 Applies to: Paradox 7.32 and later
 
   
 
Audience: Intermediate
 
       
   

Question: How do I control the shortcut menus Paradox displays when I right-click a field in a form? Can I customize them? If so, how?

Answer: Control the default shortcut menus by overridding the editProperties action, the event triggered by right-clicking an object. To illustrate, the following code sample hides the default shortcut menus for all objects on a form:

method action(var eventInfo ActionEvent)

if eventInfo.isPreFilter() then
  ;// This code executes for each object on the form

    if eventInfo.id() = editProperties then
       eventinfo.setErrorCode( userError )
    endIf

  else
  ;// This code executes only for the form

  endIf

endMethod

This example, which also contains the default code for all form-level events, evaluates the action that triggered the event. If the event was triggered by a right-clicking an object, this leads to an editProperties action. Setting an error condition prevents editProperties from doing its job. In turn, this prevents the shortcut menus from appearing.

You can replace the default shortcut menus by creating and display a custom menu in the same event. The following example demonstrates this by replacing the default shortcut menus with a record navigation menu:

method action(var eventInfo ActionEvent)

var
   siID SmallInt
endVar

if eventInfo.isPreFilter() then

  if eventInfo.id() = editProperties then

    eventInfo.setErrorCode( userError )
    switchMenu

      case "First Record"   : siID = DataBegin
      case "Scroll Back"    : siID = DataFastBackward
      case "Prior Record"   : siID = DataPriorRecord
      case "Next Record"    : siID = DataNextRecord
      case "Scroll Forward" : siID = DataFastForward
      case "Last Record"    : siID = DataEnd

    otherwise : siID = -1

    endSwitchMenu
    if siID <> -1 then
      active.postAction( siID )
    endIf

  endif

else
  ;// This code executes only for the form

endIf

endMethod

Notice that this example also sets the error condition that prevents the default shortcut menus from appearing. When overriding Paradox's default behavior, it's important to remember to handle the original behavior; otherwise, the default behavior still occurs.

Other Approaches

It's also possible to control the shortcut menus by overriding the physical event that displays them, such as mouseRightClick(). The following code sample achieves a similar results as the first example in the article:

method mouseRightUp(var eventInfo MouseEvent)

   if eventInfo.isPreFilter() then
      ;// This code executes for each object on the form

      eventInfo.setErrorCode( userError )

   else
      ;// This code executes only for the form

   endIf

endMethod

However, this may not be the most ideal place for your code, primarily because there's more than one way to display shortcut menus with Paradox. You can display shortcut menus by:

  • Right-clicking objects.

  • Pressing F6.

  • Pressing Ctrl+M.

If you block your menus by overriding the MouseRightClick() event, you run the risk of using a different approach to display the default shortcut menus. Overriding the EditProperties action, however, handles all triggers that display shortcut menus.

 

       

Top

Feedback About Paradox Delphi Assorted Web Stuff
 
 
Copyright © 2000-2004, techtricks.com; All Rights Reserved.
Acknowledgements, Disclaimers, Terms and Conditions.
Article last updated on 25 March 2004

 

Other Sites: Paradox, Delphi, Perl, Web Stuff, and More


 

[- End -]