PRB: Formset.LOAD Is Not the First Event to Fire (129571)



The information in this article applies to:

  • Microsoft Visual FoxPro for Windows 3.0

This article was previously published under Q129571

SYMPTOMS

When a form set contains a Data Environment, the BeforeOpenTables event and the OpenTables method of the Data Environment are triggered before the Load event of the form set. This article explains the reason behind this implementation and offers a workaround if you want the Load event to execute before the tables are opened.

CAUSE

The Load event of a form set usually sets the environment of a form. In particular, it can be used to bind data to controls on a form. Therefore, in most cases, tables and views must be loaded before the LOAD event of a form set is executed. Thus, the OpenTables method of the data environment is, by default, called before the Load event of the form set is executed.

WORKAROUND

If you do not want the tables or views to be opened when the Load event of a form set is executed, set the AutoOpenTables property of the form to .F.. You can then call the OpenTables method of the data environment to open the tables automatically. For example, use the following command in any method of the form:
   THISFORMSET.DataEnvironment.Opentables
				

STATUS

This behavior is by design.

MORE INFORMATION

Following is the sequence of events that are executed when a form set created in Visual FoxPro version 3.0 is loaded or unloaded. The order of events might differ if the form is converted from a FoxPro version 2.x screen. In this example, the form set is named FORMSET1 and contains a form named FORM1 and a data environment called DATAENVIRONMENT. This list was generated by executing the following code for the following events and methods:
   ACTIVATE SCREEN
   ?PROGRAM()

   FORMSET1.LOAD
   .DATAENVIRONMENT.OPENTABLES
   .DATAENVIRONMENT.BEFOREOPENTABLES
   FORMSET1.FORM1.LOAD
   FORMSET1.DATAENVIRONMENT.INIT
   FORMSET1.FORM1.INIT
   FORMSET1.INIT
   FORMSET1.SHOW
   FORMSET1.ACTIVATE
   FORMSET1.FORM1.ACTIVATE
   FORMSET1.FORM1.GOTFOCUS
   FORMSET1.FORM1.QUERYUNLOAD
   FORMSET1.DESTROY
   FORMSET1.FORM1.DESTROY
   FORMSET1.FORM1.UNLOAD
   FORMSET1.UNLOAD
   FORMSET1.DATAENVIRONMENT.CLOSETABLES
   FORMSET1.DATAENVIRONMENT.AFTERCLOSETABLES
   FORMSET1.DATAENVIRONMENT.DESTROY
				
NOTE: The OPENTABLES method calls the BEFOREPOPENTABLES event before the tables are actually opened. However, the code in the event handler is executed before the tables are opened, and this is the reason why OPENTABLES prints before BEFOREOPENTABLES prints.

For more information about the sequence of events that are triggered when a form runs, execute the sample program called EVENTS.SCX located in the SAMPLES\CONTROLS\EVENTS directory.

Modification Type:MajorLast Reviewed:2/12/2000
Keywords:KB129571