Published on InterSystems Developer Community (https://community.intersystems.com)

Home > Unable to store (or rather retrieve) OREF in globals - Trying to create a Singleton Class.

Question
AndreClaude Gendron · Apr 19, 2016

Unable to store (or rather retrieve) OREF in globals - Trying to create a Singleton Class.

We are trying to create a simple class extending %RegisteredObject that could be used as a singleton. However we are not able to store it in a global to later be retrieved (by the same process but elsewhere in the code).

I resumed my issue in this small code sample : 

ClassMethod RunMe()
{
   // Create a simple %RegisteredObject
   set obj = ##class(%ZEN.proxyObject).%New()
   set obj.MyProp = 22
   do ##class(%SYSTEM.OBJ).Dump(obj)
   
   // Store it in a global
   set ^MyGlobalName = obj
   write "Stored : " _ obj,!!
      
   // Retrieve it from the global
   #Dim obj2 As %ZEN.proxyObject = ^MyGlobalName
   write "Got : " _ obj2,!
   do ##class(%SYSTEM.OBJ).Dump(obj2)
}

Which lead to the following output when executed : 

E xecuting ##class(chs.Fw.EnsExt.Lib.CResultSetTools).RunMe()
+----------------- general information ---------------
| oref value: 1
| class name: %ZEN.proxyObject
| reference count: 1
+----------------- attribute values ------------------
| %changed = 1
| %data("MyProp") = 22
| %index = ""
Stored : 1@%ZEN.proxyObject

Got : 1@%ZEN.proxyObject
'1@%ZEN.proxyObject' is not an oref value.

I'm open to all suggestions ! Any help would be more than welcomed ! Kind regards

André-Claude Gendron

#Globals #Object Data Model #ObjectScript #Caché

Source URL:https://community.intersystems.com/post/unable-store-or-rather-retrieve-oref-globals-trying-create-singleton-class