Function called on open form event.


PUBLIC FUNCTION dlgEvent_OnOpenForm( 
   currentForm ui.FORM )

The function has one parameter:

  1. currentForm. This is a ui.FORM object referencing the current form. For more information, see The Form class in Genero Business Development Language User Guide.


When you select the On Open Form property for the creation of the event, a function shell is created. Enter your code in the function.

This function is called to initialize the form by changing the appearance or behavior of items in the form.

Example: On Open Form

This example uses the On Open Form code event for the Account form in the OfficeStore demo.

In this example, the function sets the window title text. There is a call to the user-defined function saveDefaultStyles to store the original presentation styles of some form elements.

If presentation styles may be changed, for example, to highlight required elements when adding a new record (dlgEvent_OnActionNew), the original presentation styles must be saved here in the On Open Form. Later the original presentation styles can be restored, as shown in the code sample in dlgEvent_OnActionAccept, dlgEvent_OnActionCancel, and dlgEvent_OnActionQuery events.

Two user-defined variables are defined as module variables in the AccountForm.4gl to handle the change of presentation styles in the specified form elements:
  • m_frmElements is set with the name of some elements in the form.
  • m_frmElementsStyle stores the original presentation styles of the m_frmElements elements in the call to the saveDefaultStyles function.

# AccountForm.4gl

-- import user-defined functions
IMPORT FGL myAccountFunc

# user defined module variables 
   ["account_userid_label1", "account_lastname_label1", "account_email_label1", "account_state_label1"] 
    -- form elements
DEFINE m_frmElementsStyle DYNAMIC ARRAY OF STRING --Saved styles

# ...

PUBLIC FUNCTION dlgEvent_OnOpenForm(currentForm ui.form)

     DEFINE w ui.Window
     DEFINE n om.DomNode

     CALL libdbappCore.log(C_LOG_INFO, "dlgEvent_OnOpenForm (Form scope) is raised")

     LET w = ui.Window.getCurrent()
     CALL w.setText("Customer accounts")
     CALL myAccountFunc.saveDefaultStyles(currentForm,m_frmElements,m_frmElementsStyle)
     CALL libdbappCore.log(C_LOG_INFO, "dlgEvent_OnOpenForm (Form scope) is exited")


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

In this section there is an example of the function saveDefaultStyles called to store the original presentation styles of some form elements.

The saveDefaultStyles function references two parameters:
  • The lbllist array that stores a list of form elements.
  • The lblStylelist array where it stores the original presentation styles of lbllist.
All functions that you would reuse across forms and applications would reside in a module you create. To use these functions in your project, you would import your module into the entity module (for example, AccountForm.4gl) using the IMPORT FGL statement.
# MyAccountFunc.4gl

FUNCTION saveDefaultStyles(currentForm ui.Form, lbllist DYNAMIC ARRAY OF STRING,
                                     lblStylelist DYNAMIC ARRAY OF STRING)
    DEFINE n om.DomNode

    FOR i = 1 TO lbllist.getLength()
      LET n = currentForm.findNode("Label", lbllist[i])
      LET lblStylelist[i] = n.getAttribute("style")