Public
Snippet $11 authored by Jackson Romie

Object Cleanup with Scripting

file
Business objects and service objects created during scripting are cleaned up when the session is released which happens when the pvx com object (generally, handle to object is held in corresponding pvxwin32.exe instance) is released.

When using the same business object class in the same session, there are two options:
Create and drop each object within the scope of the script
Reuse a single object throughout each instance of the script
Take special care to clear the edit state of the object to avoid collisions with other objects.

Note: I have not tested how GetObject works when there are two different instances of the same business object. If the wrong object is selected, the process that created that object may exhibit unusual behavior. Further testing is necessary here.

OPTION 1:

oBillInternal = oSession.NewObject("BM_Bill_bus")
If oBillInternal <> 0 Then
	SET oBill = oSession.AsObject(oBillInternal)
Else
	MSGBOX “Initialization Failure”
End If

‘ example operations
retVal = oBill.MoveFirst()
retVal = oBill.MoveNext()
key = ""
key = oBill.GetKey()
MSGBOX key

retVal = oSession.DropObject(oBillInternal)
‘ drop object may fail, but object appears to be released anyways

OPTION 2:

‘ find existing object or create a new object if necessary
oBillInternal = oSession.GetObject(“BM_Bill_bus”)
If oBillInternal <> 0 Then
	SET oBill = oSession.AsObject(oBillInternal)
Else
	MSGBOX “Initialization Failure”
End If

‘example operations
retVal = oBill.MoveFirst()
retVal = oBill.MoveNext()
key = ""
key = oBill.GetKey()
MSGBOX key

‘ Note that this doesn’t drop the object from the internal object collection
‘ maintained by the current session, it only clears the edit state.
retVal = oBill.Clear()