3-Lib banner

The Absolute Beginners Guide to OPL

P103 - OPL/16 - Menus for real


These tutorials use the 16-bit version of RMR Software's excellent "RMREvent" example program, disecting it bit by bit to show you how and why it works. Make sure you've got the latest version, v1.00.

We detected the [Menu] keypress last time, simply calling a procedure called Menu: . One of the trickiest parts of setting up a professional OPL program is always giving the user as consistent an interface as possible. For example, he or she should always have the choice of using menu options or corresponding [Psion][key] hotkeys and wherever possible these hotkeys should match similar functions in the built-in applications (e.g. [Psion]-[N] for 'New file'). Let's look at RMREvent's menu system. Find the Menu: procedure:

Screen shot

Short, isn't it? The user's asked for a menu so that's exactly what we give them. Note a few points in particular:

Screen shot

Being able to use an application framework like RMREvent is at its most useful when setting up code to handle keys and menus. By simply replacing RMREvent's menu options with your own and then calling your custom procedures, it should be possible to produce a working real-world program in a small fraction of the time it would take to write it from scratch, even as an experienced user.

Note as well that in a real-world program you'll also want to have a third way of interacting with the program, i.e. the use of the cursor keys, [Tab], [Enter] etc. to allow navigation round your application's screens. Each of these keypresses is just trapped in the way already described, inside the main event loop, and custom procedures and commands called as appropriate.

So where have we got to? We've seen how to trap keypresses directly and to determine from the user what he or she wants to happen next. Let's look at a typical example. Say the user presses [Psion][N] or selects 'New file' from the RMREvent menu. Our event loop then calls the procedure Newfile:

Screen shot

Like many of your own custom procedures, this is just a short routine to do a specific job. Here we want to ask for a new file name and, if one is supplied, to create it. There are a few bits to note especially:

Having finished its file creation job, the procedure then returns control back to the all-powerful event loop described earlier. At which point the whole cycle starts again.

See you next week, when we'll be looking at handling the Series 3 status window and zoom functions.


Go to next lesson | Programming index