In an application, the form is the primary user-interface component. Forms contain components, or controls, such as entry fields and pushbuttons, with which the user can interact. The controls recognize events, such as mouse clicks or key presses.

You attach code to event handlers of controls, such as OnClick or OnLeftMouseDown (most begin with On), that correspond to specific events. For instance, when a user clicks a pushbutton, the OnClick event handler executes.

Specifying event handlers for forms is similar to using the ON commands in dBASE DOS, such as ON KEY LABEL or ON ERROR. Like an event handler, the ON command designates some program code to execute when an event, such as a keypress or a run-time error, occurs. However, the events handled by the ON commands are limited and are not associated with user-interface objects.

In a typical event-driven application,

  1. The application automatically displays a start-up form.

  2. The form, or a control on the form, receives an event, such as a mouse click or keystroke.

  3. An event handler associated with the event in step 2 executes.

  4. The application waits for the next event.

Imagine a sample "Hello world!" form with one pushbutton on it that is labeled "Goodbye". After displaying the form, dBASE Plus waits for an event. The user can move, resize, minimize, or maximize the form. When the user clicks the pushbutton, dBASE Plus executes the OnClick event.

The following code, a .WFM file generated by the Form designer, creates the form just described . This code follows the general structure of all forms generated by the Form designer. For now, donít try to understand every line. Just look at the general structure to get a sense of how forms are created, properties are set, and event handlers are assigned to events.

parameter bModal

local f

f = new Hello( )

if (bModal)

f.mdi = .F. && ensure not MDI 

f.ReadModal( ) 

else

f.Open( ) 

endif

CLASS Hello OF FORM

with (this) 

Height = 16 

Left = 30 

Top = 0 

Width = 40 

Text = "My first dBASE Plus form"

EndWith 

this.TEXT1 = new TEXT(this) 

With (this.TEXT1) 

Height = 3 

Left = 11 

Top = 3 

Width = 33 

Metric = 0 

ColorNormal = "N/W" 

FontSize = 23 

Text = "Hello world!" 

EndWith 

this.BUTTON1 = new PUSHBUTTON(this) 

With (this.BUTTON1) 

onClick = class::BUTTON1_ONCLICK 

Height = 2 

Left = 19 

Top = 9 

Width = 13 

Text = "Goodbye" 

Metric = 0 

StatusMessage = "Click button to exit" 

Group = True 

EndWith 

// {Linked Method} Form.button1.onClick 

Function Button1_OnClick  

DO WHILE (Form.Height > 0) .AND. (Form.Width > 0) 

Form.Text1.Text = "Goodbye" 

Form.Height = Form.Height - 1 

Form.Width = Form.Width - 1 

Form.Top = Form.Top + .5 

Form.Left = Form.Left + .5 

ENDDO 

Form.Close( ) 

  return

ENDCLASS