Form Events

Description

A form's OnInit event occurs when a form is loaded. On the Customer Information form the OnInit event runs Xbasic code that initializes the display.

  • It defines the vcSearchBy variable and gives it a default value.

  • It sorts the Customer table on the field defined by vcSearchBy.

A form's CanExit event occurs when a user or program attempts to close a form. The CanExit event gives you the opportunity to prevent the close, by invoking the cancel() function. The Customer Information form's CanExit event makes sure that the shipping address is complete before the user closes the form:

  • Checks to see if the billing and shipping address are different.

  • If true, tests to see if the Ship_Address_1 or Ship_City fields are blank.

  • If true, notifies the user and stops the form close.

Xbasic Code Run by the Customer Information Form CanExit Event 

This is the Xbasic code from the CanExit event.

dim tbl as P

tbl = table.current()
if (tbl.SHIP_SAME = .f.) then
    if (tbl.SHIP_ADDRESS_1 = "") .or. (tbl.SHIP_CITY = "") then
        msg = "Shipping address is incomplete. If shipping address is same as billing address, check the 'Same as billing' box."
        ui_msg_box("Error", msg,UI_STOP_SYMBOL)
        cancel()
    end if
end if

An Explanation of the Code 

The first line creates a pointer variable named tbl to refer to table (and the data) that the Customer Information form displays.

dim tbl as P

Each form is based upon a table (or set). The Customer Information form is based on the Customer table. This line points tbl at the Customer table.

tbl = table.current()

Check the Ship_Same field of the table to see if the shipping and billing addresses are supposed to be the same. If the answer is false, then:

if (tbl.SHIP_SAME = .f.) then

If either of the SHIP_ADDRESS_1 or SHIP_CITY fields are NULL, then:

if (tbl.SHIP_ADDRESS_1 = "") .or. (tbl.SHIP_CITY = "") then

The shipping address must be different, prepare a warning message for the user.

msg = "Shipping address is incomplete. If shipping address is same as billing address, check the 'Same as billing' box."

Display the warning message.

ui_msg_box("Error", msg,UI_STOP_SYMBOL)

Cancel the close.

cancel()