Adding Popup Functionality to a Window
The most common use of a Popup is to provide users with a list of choices during data entry. The following procedure will demonstrate how to add a button to an existing form and the Event Handler necessary to execute the Popup and place the results within a data field.
1. Open the CUSTOMERS form and it will load in the Form Designer.
2. Select Open, OpenInsight Forms from the OpenInsight IDE. Choose the CUSTOMERS form.
3. From the Common Controls tool panel on the left side of the Form Designer select the Push Button control and drag it on to the form.
4. Place the control on the form by moving the mouse cursor to a location on the form where you want to place the control. The mouse cursor changes to the control’s icon with a + appearing to the left and above the icon as soon as the mouse cursor enters the form. The + is used to help position the control. Click the left mouse button where you want to place the control. The control is displayed in the form in the selected state (with handles visible).
5. Click on the button. The Push Button Properties window will appear in the Property Panel on the right side of the form. Change the Name of the control to “BTN_CHOOSE_CUSTOMER” and the Text that is displayed on the control to “Choose Customer”.
6. Click on the Events Tab on the Property Panel to display the QuickEvent dialog box. Under Action, Click, open the properties for the Click Event.
7. The CLICK event will be chosen by default.
8. Click on the EventScript check box. This will launch the Event Editor. In the Editor type the following code:
declare subroutine Set_Property, Send_Event
declare function Popup
retval = Popup(@window,"","CUSTOMERS")
Set_Property(@window:".EF_CUSTOMERID",”DEFPROP”,retval)
Send_Event(@window:".EF_CUSTOMERID","LOSTFOCUS")
9. Select File, Compile from the OpenInsight IDE. Any errors will be displayed in the Output Panel at the bottom of the OpenInsight IDE. If the syntax is correct the status line will display “The syntax is correct”.
This will cause a popup to display when the Choose Customers button is clicked. The user may choose a Customer. The value chosen will be placed into the EF_CUSTOMERID control on the Customers form. When the EF_CUSTOMERID field loses focus a read of the CUSTOMERID placed into the field will occur.
10. Select File, Save from the OpenInsight IDE. This will save the code. Click the View Form button on the Toolbar to return to the form.
11. Choose File, Save to save the form.
12. Test run the form and click the Choose Customer button to launch the popup. Select a record, click OK and the record will be read and loaded into the form.