dlgEvent_OnOpenForm

Function called on open form event.

Syntax

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.

Usage

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 text, hides some elements of the form, and saves the original presentation styles of some elements.

If presentation styles may be changed in other events, for an example see the code sample in the dlgEvent_OnActionNew, the original presentation styles must be saved here in the On Open Form event.

Two user-defined variables are defined as module variables in the AccountForm.4gl:

  • m_frmElements stores the name of some elements in the form
  • m_frmElementsStyle stores the original presentation styles of the m_frmElements elements

Later the original presentation styles in m_frmElementsStyle can be restored, as shown in the code sample in dlgEvent_OnActionAccept, dlgEvent_OnActionCancel, and dlgEvent_OnActionQuery events.


# AccountForm.4gl

# user defined module variables 
DEFINE m_frmElements DYNAMIC ARRAY OF STRING = 
   ["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

     DISPLAY "dlgEvent_OnOpenForm (Form scope) is raised"

     LET w = ui.Window.getCurrent()
     CALL w.setText("Customer accounts")
     CALL currentForm.setElementHidden("Label17", 1)
     CALL currentForm.setElementHidden("account.sourceapp",1)

     # This sample code may be written instead in a function that
                    you call. 
     # The function would be in a module shared by forms and
                    applications, and imported using the IMPORT FGL statement.
     # Save style of m_frmElements
     FOR i = 1 TO m_frmElements.getLength()
       LET n = currentForm.findNode("Label", m_frmElements[i])
       LET m_frmElementsStyle[i] = n.getAttribute("style")
     END FOR

     # End user code

     DISPLAY "dlgEvent_OnOpenForm (Form scope) is exited"

END FUNCTION