Omnis Technical Note TNGI0016 April 2007

Programming without the Enter Data command

For Omnis Studio 3 or above
By Andreas Pfeiffer

Quite often we are asked how to use the Enter Data command, for example, to implement a search window which provides more functionality than just a simple Yes/No request. Remember - this is exactly the key purpose of the Enter Data command: it stops the code! In this context, the Enter Data command is used for a special purpose: it stops code execution and can allow the user to enter some data or make a selection in a separate window before code execution is allowed to continue.

Halting code execution and popping up a separate query window shouldn't be a problem, but such a query window requires its own event handling. Such a combination of windows can be difficult to debug. Maybe you remember the old Omnis 7 technique of coding as much as possible into the so called "window control procedure". Something like that is almost impossible to debug.

Another problem concerns the main routine. Many developers tend to extend this routine more and more because it seems so easy to interrupt the code processing for any user input. But this results in very long methods which could much better be placed in separate objects or methods.

Let's look at an example in detail. You may have an address window which displays one record at a time. You could implement a method that takes care of the search. You could start this method with a button. At some point within the method a window will be opened, code execution is stopped, and the window will be closed when the user has pressed the OK button - and then the method will start loading the selected record.

With this technique you have included three tasks into one single method, and the code will probably be quite long and complex. It would be so much easier to pass over the entire handling to the search window and to only provide one so-called callback routine in the main window.

To achieve this, simply create a method called $load in your address window. This method gets the primary key as a parameter and then loads the appropriate record. The button to open the search window would pass a reference of the current instance as a parameter to the search window. This way we have only got two lines of code behind the search button and the search routine can be added to the search window without having to stop the code at all.

On evClick
 Do $windows.wSearch.$open("*",kWindowNormal,$cinst)

The $construct() method of the search window has got a parameter of the type Item Reference that receives the reference of the calling window and copies it into an instance variable of the type Item Reference:

Set reference ivCallingInstanceRef to pCallingInstanceRef.$ref
; Note the "$ref" after the parameter.

After the search has completed successfully, a method of the search window can call the method $load via the reference to the address window:

Do ivCallingInstance.$load(ivDataList.primaryKey)

Typically, routines such as $load will be stored in a superclass so that they are available globally for all instances in your application.

Now we have got two quite short methods in the address window which take care of the search functions: one that opens the search window without Enter Data, and another one which is called by the search window and which loads the record from the server.

In case we may want to change the search completely at some time we can just edit the search window without having to modify the other routines. But it is important to make sure that the $load of ivCallingInstance is triggered at the end of the method.

Search Omnis Developer Resources

 

Hit enter to search

X