Hacker’s Guide to Visual FoxPro
An irreverent look at how Visual FoxPro really works. Tells you the inside scoop on every command, function, property, event and method of Visual FoxPro.
This is one of the coolest of the SYS() Functions
. Added in version 5.0, it lets us call system menu bars without having to KEYBOARD their hot keys or shortcuts. It’s especially useful for toolbars and context menus.
cEmptyString = SYS( 1500, cMenuBarName, cMenuPopupName )
Parameter |
Value |
Meaning |
cMenuBarName |
Character |
The name (not the prompt) of the actual menu item you want to use. |
cMenuPopupName |
Character |
The name (not the prompt) of the menu popup that contains the item. |
cEmptyString |
Character |
No matter what it does or doesn't do, the function returns the empty string. |
The system menu has some great capabilities built into it, things like undo/redo and cut/copy/paste. We often want to include these items in our applications but call on them from places other than the menu, such as a standard toolbar or a context (right-click) menu. Before SYS(1500) came along, we either had to write our own code to emulate VFP’s or KEYBOARD appropriate keystrokes to call the menu item. In many cases, writing our own code was a truly daunting task. As for KEYBOARDing the right keystrokes, we could and did do it, but it was one more thing that made our apps more fragile than necessary. Among other things, the hot keys for different items vary in different languages.
SYS(1500) provides a simple, straightforward solution. Just call on the menu item directly. There is one caveat. As with the KEYBOARD approach, the menu item must be available. If you haven’t included _MED_UNDO on the Edit popup (_MEDIT), you can’t issue SYS(1500,”_MED_UNDO”,”_MEDIT”). However, as with other menu tricks, the item doesn’t actually have to be visible to be used; it only has to be defined.
VFP provides somewhat more flexibility here than we expected. The menu bar itself has to have its usual assigned name (like _MED_UNDO), but the popup can have any name. In addition, the menu bar doesn’t have to be on the popup where it’s usually found. You can rename the popup or move the item to a different popup and still use this function. Just make sure to specify the right popup name in the function call. (Of course, there are user interface reasons why you normally want to leave the bars on their default menu popups.)
Be aware that the function doesn’t give you a clue whether or not it was successful. If you pass it a nonexistent menu bar or popup, there’s no error message, no special return value, no nothing. If it’s important to make sure the action you’re calling on happens, you’ll want to test for the existence of the appropriate menu bar/popup pair beforehand. Check out POPUP and GETBAR()
for some ideas how to do that.
* The Click method for a Paste button might contain:
SYS(1500,"_MED_PASTE","_MEDIT")