Contents
Form Array  Sample Help

Sample Description: Form Array

Points of Interest

Creating a Form Array

Removing Form Instances

Control

Form

For Help on Help, Press F1


Form Array

This Form Array sample is intended to show how to create and delete forms through program code. There may be times in your application, that you may wish to create copies of existing forms, and then remove them when they are no longer needed.

Several objects and methods exist in Envelop to help you manipulate objects. This sample will show you how a few of them work.


Creating a Form Array

In this sample, a Create button is used to issue the following program code:

Sub btnCreate_Click()

  Dim s As String

  Dim o As Object

  s = UniqueObjectName(ArrayFormMasterForm)

  o = CopyObject(ArrayFormMasterForm, s)

  o.Show

  o.Move Left + (Width / 10), Top + (Height / 10), Width, Height

  o.BackColor = RGB(rnd() * 256, rnd() * 256, rnd() * 256)

End Sub

The program code above shows how the form ArrayFormMasterForm can be copied. The method UniqueObjectName is defined by Globals/ObjectTools as follows:

Function UniqueObjectName(ByVal o As Object) As String

  ' Source not available

End Function

The purpose of this function is to return a unique object name based on the object name it is passed. The method CopyObject is used to create a copy of an existing object. The object can be a form, or can be some type of control or other object. The CopyObject method takes both the object and the name the object is to be given as shown below:

Function CopyObject(ByVal o As Object, ByVal optname As String) As Object

  ' Source not available

End Function

The remaining program code simply displays the newly created object, moves it into position on the screen, and sets the background color to some random color. This is simply to help highlight the arrival of the copied form.


Removing Form Instances

Removing objects in Envelop applications is a easy as creating them. Once again, a common method called DestroyObject, which is defined by Globals/ObjectTools, was used. The following program code is activated when the Close button is clicked in the sample. This sample presents a special case, whereby the original form (ArrayFormMasterForm) cannot be removed from the screen. The remove functionality is performed in the following click method:

Sub btnDelete_Click()

  ' If the form is a copy of ArrayFormMasterForm, then destroy it otherwise hide it

  If Me == ArrayFormMasterForm Then

      ' Do nothing

  Else

      DestroyObject(Me)

  End If

End Sub

There are several additional object methods that manipulate objects. They are listed with the Globals/ObjectTools object.