If you wish to use class instantiations, controls or components you must assign an object reference to a variable or property by using the set statement and the IsahObjects.Get function.
Before you use the set statement you must first use the dim statement to declare the variable that refers to the object.
For example:
Dim
oParamNewFieldDate
Set
oParamNewFieldDate = IsahObjects.Get("IsahDateTimeField
")
Generally, if you use 'set to assign an object reference' to a variable, no copy of the object will be created for that variable. Instead, a reference to the object will be created. At the end of the script (or function or procedure depending of the object scope) you must destroy all assigned object references.
Again use the set statement to discontinue the association of a variable with any specific object (destroy or clean up the object references). Assigning the variable to 'Nothing' releases all the system and memory resources associated with the previously referenced object when no other variable refers to it.
For example:
Set
oParamNewFieldDate = Nothing
Furthermore, it is important to destroy objects in the correct order. If you assign an object reference to variable var1 and on the next line you assign another object reference to variable var2, you must first destroy the reference to var2 and then the reference to var1. In general, you have to destroy objects in an order opposite to the reference creation order.
For example:
Dim
oParamNewFieldDate1
Dim
oParamNewFieldDate2
Dim
oParamNewFieldDate3
Set
oParamNewFieldDate1 = IsahObjects.Get
("IsahDateTimeField
")
Set
oParamNewFieldDate2 = IsahObjects.Get
("IsahDateTimeField
")
Set
oParamNewFieldDate3 = IsahObjects.Get
("IsahDateTimeField
")
Set
oParamNewFieldDate3 = Nothing
Set
oParamNewFieldDate2 = Nothing
Set
oParamNewFieldDate1 = Nothing
When building custom forms (with instances of TFORMS), many objects are involved. All these objects have to be created and destroyed properly in the correct order. In addition, there are ownership relations between parent and child objects. If a parent object is destroyed, its child objects must also be destroyed. However, you don't have to manage the ownership relations yourself.
The Script Engine uses the Delphi Load mechanism for managing ownership of forms and their (visual) components. By using this mechanism (visual) components are released from memory in the correct order when the form is destroyed. Form based scripts that are generated with the Script IDE contain the statements for activating the Load mechanism by default. If you create a form based script manually use the following property settings:
For example:
Dim
frmEdit, dtpFieldDate
Sub
main
rem Create the form
Set
frmEdit = IsahObjects.Get
("EditFormObject
")
frmEdit.Loading = True
rem Initialize the components
Set
dtpFieldDate = IsahObjects.Get
("TDateTimePicker
")
With
dtpFieldDate
.Parent = frmEdit
.Name = "dtpFieldDate
"
.Left
= 8
.Top = 48
.Width = 186
.Height = 21
.Date
= 38777.680824108790000000
.Time
= 38777.680824108790000000
.TabOrder = 0
End With
rem initialize more components...
frmEdit.Loading = False
rem more code...
Rem destroy objects
Set
frmEdit = nothing
End Sub