$doctitle = "Controlling Shortcut Menus"; $authname = 'Lance Leonard'; $attrinfo = ""; // 0=All, 1=New, 2=Intermediate, 3=Expert, 4=Developers Only $audience = "2"; $versions = "Applies to: Paradox 7.32 and later"; $postdate = "25 February 2003"; $pagearea = 2; $navlinks = 'Paradox:'; $metakeys = "corel paradox, borland paradox, paradox, pdoxwin, borland, corel, menu, right click, shortcut menu, short, cut, menu, right click, right, click, control, override, create, handle, block, prevent, hide, ObjectPAL, forms, form, action, popup menu, popup, event model, event, events, model, action, postAction, right click"; $metadesc = "Shows how to control (and block) right-click (shortcut) menus in Paradox forms."; ?> include( $DOCUMENT_ROOT . "/lib/pageinit.php" ); ?>
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
endMethodThis 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
endMethodNotice 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.
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
endMethodHowever, 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.
include( $DOCUMENT_ROOT . "/lib/pagecomp.php" ); ?>