Load Statement

Loads a form.

Syntax

Load frmVar [, [bModal] [,Parent ]]

Comments

The Load statement creates a form object and a form window. The type of the form variable frmVar determines which form will be loaded. The type is the name of the form that appears below the Forms submodule. If frmVar has a value of Nothing, then a new form object is created and the form object is stored in frmVar. The form is then initialized and the form window and its controls and menus are created. Unless the Visible property for the form is turned off at design time, the form is made visible.

If the optional Bool argument bModal is true (the default value), the form is loaded as a modal form. When a form is modal, the Load statement will not return and the next line of code after the Load statement will not be executed until the form is unloaded and its window is destroyed. However, form events can be called and executed during that time.

If the bModal argument is false, the form is loaded as a modeless form and the Load statement returns immediately after the form is loaded. When an event is received, the current code is interrupted and the form event procedure is called. Once the form event procedure is returned, the execution resumes. Loading a form in modal mode will always disable all windows that are  created before, forcing users to close the window before working on other windows.

The optional Parent argument is a window handle or a form object that will be used as a parent or owner window for the new form window created on top of its parent/owner window. Omitting this argument indicates to use the Form internal variable as a parent. If the Load is not called from within a form ATEasy will use the current active top-level window as a parent that was created from within this thread. Specifying 0 as an argument indicates that the desktop window is used as a parent.

The created form is always displayed on top of its parent form. In addition, if the form is created as a modal form, its parent window will be disabled and will not receive any user input until the form is unloaded. If the parent form is closed than the current form is also unload automatically.

After the Load statement is called, the form object is created and the OnInitialize event procedure is called. Then the form window is created and the OnLoad event procedure is called. The form is visible if the Visible property is set to True and only after the OnLoad procedure is returned.

If the frmVar has a value that is different than Nothing the form will be reload. Reloading a form will create the form window only if it is not already created, the form variables and members will not reinitialized if they are already created. If you need to initialize the form members and the form you create is modeless you can load the form in modeless mode, than initialize it’s members and then load it again in modeless mode (see example below).

Please refer Loading and Unloading Events for forms' events and their order when a form is created and closed.

In addition to examples below, more examples for forms are in the forms.prj example in ATEasy Examples directory.

Examples

The following example creates a modal form called Profile Editor (m_frmProfileEditor) on top of the current form:
 

Load m_frmProfileEditor

! we get here after the form window is closed – since this is a modal form

If m_frmProfileEditor.f_bCanceled    ! check member

    ! do something

EndIf

m_frmProfileEditor=Nothing     ! done with the form - release its memory

The following example shows : create a modeless form, frm (a local variable) and stay in the loop until frm.f_bWait being set to False:
 

Load frm, False, 0     ! create modeless on the desktop

! initialize mebers

frm.f_iCount=m_iCount      

frm.Initialize()       !  call a form procedure initialize

frm.Visible=True       ! make it visible

frm.Refresh()

while frm.hWnd and frm.f_bWait

DoEvents()

WaitForEvent() ! don't consume 100% cpu

Endwhile

m_iCount=frm.iCount

frm=Nothing

The following example shows how to create a modal form and set its variables and properties :
 

load frmModal, false      ! create modless so we can set form members

frmModal.Tag="hello"      ! set tag

frmModal.lVariable=120    ! set member variable

load frmModal, true       ! now make it modal

! place code after the form window is close

Print frmModal.lVariable

frmModal=Nothing

The following example creates two forms the second one will behave similar to modal but will disable only it’s parent and not all the currently displayed forms :
 

load frmParent1, False ! create first form

frmParent1.Enabled=False

load frmParent2, False, 0  ! create 2nd form with desktop parent

frmParent2.Caption="hello"

! wait until form 1 is closed

while frmParent2.hWnd

DoEvents()

WaitForEvent() !do not consume 100% cpu

endwhile
 

! form 2 was closed now enable form 1 and activate

frmParent1.Enabled=True

frmParent1.Visible=True

! wait until from 1 is closed

while frmParent1.hWnd

DoEvents()

WaitForEvent() !do not consume 100% cpu

endwhile

See Also

AForm, OnInitialize, OnLoad, OnQueryUnload, OnTerminate, OnUnload, Unload, DoEvents, WaitForEvents, Loading and Unloading Events