CANCEL()

Syntax

CANCEL( [ No_Error as L ] )

Argument

Description

No_Error

Optional. Default = .T. Whether to suppress error messages.

  • .T. = Suppress Alpha Five error messages.

  • .F. = Display error messages.

Description

The CANCEL() command sets the Alpha Five system variable A_CAN_DO to "NO".

All of the events whose names are prefixed with "Can" can be canceled, thus preventing the event from occurring. The CANCEL() command is used to cancel an event.

The CANCEL() command can take an optional flag which can be .T. or .F. If the flag is set to .T. then Alpha Five error messages are suppressed. When you cancel an event, if your Xbasic code provides the appropriate feedback to the end-user as to why the event is being canceled (for example, by including a UI_MSG_BOX()in the code), then you would not want additional error reporting from Alpha Five itself. In this case, you would use CANCEL(.T.) in your code to cancel the event.

Supported By

Alpha Five Version 5 and Above

Limitations

Desktop applications only.

Example

For example, assume that you have a control on a form and that you define a script for that control’s CanDepart event. Assume that the control has focus and that the user tries to give focus to another control on the form. This will cause the control’s CanDepart event to fire. If this script executes the CANCEL() command, the event will be canceled and the user will not be able to move focus away from this control.

The following example shows how a script could be attached to a table’s CanDeleteRecord event. When the user deletes a record, the script is executed. It displays a dialog box asking the user for the password. If he enters the correct password, the record is deleted. Otherwise, the Delete event is canceled and the record is retained.

This script prompts the user for a password before deleting a record.

password = "Alpha5"

user = UI_GET_text("Password", "Enter the password", "******", "&&&&&&")

if (user = "") then

    end

end if

if (.not.(user == password)) then

    cancel()

    ui_msg_box("Password", "Password invalid.")

end if

A Solution for Required Fields

This script is attached to a form's CanSave event and checks the values of three required fields: field1, field2, and field3.

if isNULL(field1) .or isNULL(field2) .or. isNULL(field3) then

    cancel()

end if

See Also

Canceling Events, UI_MSG_BOX()