Click or drag to resize

IMcObjectsMcObjectFromHOBJ Method

A method to get a particular McObject instance from its InternalHOBJ property.

Namespace:  MediaCy.IQL.ObjectManager
Assembly:  MediaCy.IQL.ObjectManager (in MediaCy.IQL.ObjectManager.dll) Version: 10.0.6912.0
Syntax
VB
Function McObjectFromHOBJ ( 
	HOBJtoLookUp As IntPtr
) As McObject

Parameters

HOBJtoLookUp
Type: SystemIntPtr
The InternalHOBJ property for the desired McObject.

Return Value

Type: McObject
The McObject instance which has the supplied HOBJtoLookUp as its InternalHOBJ property, or Nothing if no such McObject exists or if the McObject that did have that InternalHOBJ has been killed (with KillObjectAndChildren).
Remarks
This method provides a safe way to determine if a particular McObject instance is still functional and still exists without having to keep a reference on the instance (and thereby forcing it to keep existing). This method looks up the McObject instance, if any, that currently has the suppled HOBJtoLookUp as its McObject.InternalHOBJ property. The McObject.InternalHOBJ property is an identifier that is unique among all existing, "unkilled" McObject instances (ones where McObject.KillObjectAndChildren has not been called). If no such McObject exists or if a McObject that did have that InternalHOBJ has been killed, then Nothing is returned. Note that once a McObject has been killed or fully released, its InternalHOBJ value may be (and in fact probably will be) reused when another McObject is created. Thus, to identify a particular McObject instance, you must not only ensure that McObjectFromHOBJ does not return Nothing, but also that the returned object pointer is the same as the one you originally got the InternalHOBJ from. For this purpose, these pointer values can be treated as just a number; you do not need to (and will not want to) keep a reference on the original pointer value.
Examples
VB
' See if a McObject still exists
Sub SeeIfAoiStillExists()
Dim myObj As McObject, myHOBJ As Int_Ptr, myObjAsNumber As Long
Set myObj = ThisApplication.McObject(ActiveImage.Aoi)
myHOBJ = myObj.InternalHOBJ
myObjAsNumber = ObjPtr(myObj)
Set myObj = Nothing 'release our reference on the McObject
' See if it is still alive
Dim myObj2 As McObject, myObj2AsNumber As Long
Set myObj2 = ThisApplication.McObjects.McObjectFromHOBJ(myHOBJ)
myObj2AsNumber = ObjPtr(myObj2)
Set myObj2 = Nothing 'release our reference on the McObject
If myObj2AsNumber = myObjAsNumber Then
MsgBox "The original ThisApplication.ActiveImage.Aoi still exists and is alive."
Else
MsgBox "The original ThisApplication.ActiveImage.Aoi is no longer alive."
End If
ThisApplication.ActiveWindow.Close 'close the ThisApplication.ActiveImage and test again
' Now see if it is still alive
Set myObj2 = ThisApplication.McObjects.McObjectFromHOBJ(myHOBJ)
myObj2AsNumber = ObjPtr(myObj2)
Set myObj2 = Nothing 'release our reference on the McObject, if any
If myObj2AsNumber = myObjAsNumber Then
MsgBox "The original ThisApplication.ActiveImage.Aoi still exists and is alive."
Else
MsgBox "The original ThisApplication.ActiveImage.Aoi is no longer alive."
End If
End Sub 'SeeIfAoiStillExists
See Also