dlgEvent_record_BeforeInsert

Function called by dialog code event before user inserts a row.

Syntax

PUBLIC FUNCTION dlgEvent_record_BeforeInsert( 
   dlg ui.DIALOG, 
   uiMode SMALLINT,
   dlgCtrlInstruction libdbappEvents.DlgCtrlInstruction_Type)
  RETURNS (libdbappEvents.DlgCtrlInstruction_Type)
The function parameters are:
  1. dlg. This is a ui.DIALOG object referencing the current dialog. The dialog can implement an INPUT, INPUT ARRAY, DISPLAY ARRAY, MENU, or CONSTRUCT. For more information, see The Dialog class in Genero Business Development Language User Guide.
  2. uiMode. This is an integer value defining the current mode or state in relation to user action in the dialog, form, or application. Modes are defined as constants in the libdbappFormUI file in the libdbapp library.
    Table 1. UI modes
    Description Applies to ... Constant Value
    Display DISPLAY ARRAY C_MODE_DISPLAY 1
    Modify INPUT \ INPUT ARRAY C_MODE_MODIFY 2
    Add INPUT \ INPUT ARRAY C_MODE_ADD 3
    Search CONSTRUCT C_MODE_SEARCH 4
    Empty MENU C_MODE_EMPTY 5
    Exit form The form C_MODE_EXIT_FORM 6
    Exit app The app C_MODE_EXIT_APP 7
    Undefined All (array, form, or app) C_MODE_UNDEFINED 0
  3. dlgCtrlInstruction is a libdbappEvents.DlgCtrlInstruction_Type defining the dialog control instruction.
    Instructions available will vary depending on the uiMode:
    • For display, modify, and add mode, see Table 2.
    • For empty mode, see Table 3.
    Table 2. Dialog control instructions for display/modify/add modes
    Description Constant Value
    Accept dialog ACCEPT_DIALOG 1
    Continue dialog CONTINUE_DIALOG 2
    Exit dialog EXIT_DIALOG 3
    Cancel insert CANCEL_INSERT 6
    Table 3. Dialog control instructions for empty mode
    Description Constant Value
    Continue menu CONTINUE_MENU 4
    Exit menu EXIT_MENU 5
    Cancel insert CANCEL_INSERT 6

The function returns a dialog control instruction value defined by libdbappEvents.DlgCtrlInstruction_Type.

Usage

When you select the Before Insert Row property for the creation of the event, a function shell is created. Enter your code in the function.

This function is called when a user tries to insert a new row in a dialog. It is called before the new row is created and made current. For example, this allows you to check if the user is allowed to insert rows, and cancel the row insertion if not by returning the CANCEL_INSERT instruction.

Example: Before Insert

This example uses the Before Insert Row code event for the Account form in the OfficeStore demo.

In this example if this user is not allowed to insert rows, an error is raised and the insert is canceled in the dlgCtrlInstruction instruction that is returned. This example uses a user-defined function to verify user capabilities.

PUBLIC FUNCTION dlgEvent_recAccount_BeforeInsert(dlg ui.DIALOG, uiMode SMALLINT,
      dlgCtrlInstruction libdbappEvents.DlgCtrlInstruction_Type)
    RETURNS (libdbappEvents.DlgCtrlInstruction_Type)

   CALL libdbappCore.log(C_LOG_INFO, "dlgEvent_recAccount_BeforeInsert (Row scope) is raised")
    IF NOT user_can_insert() THEN
       ERROR "You are not allowed to insert rows"
       LET dlgCtrlInstruction = libdbappEvents.CANCEL_INSERT
    END IF      
    CALL libdbappCore.log(C_LOG_INFO, "dlgEvent_recAccount_BeforeInsert (Row scope) is exited")

    RETURN dlgCtrlInstruction
END FUNCTION

For more information on the libdbappCore.log() function, go to DBAPPDEBUG and the debug level API.