Difference between revisions of "ISDBApplication::Objects"

From MediaMonkey Wiki
Jump to: navigation, search
m (Corrected the example code for VBScript)
(Added JScript example)
Line 8: Line 8:
 
===Property description===
 
===Property description===
  
A collection for temporary storage of any type of object during MediaMonkey running time. For example if a window is created by script that should remain visible while the script isn't running, the window object can be put into this collection in order to keep a reference to it. The keys of this collection are strings, the values are objects.
+
A collection for temporary storage of any type of object during MediaMonkey running time. For example if a window is created by script that should remain visible while the script isn't running, the window object can be put into this collection in order to keep a reference to it. The keys of this collection are strings, the values can be only objects.
  
===Example code===                     
+
===Example VBScript code===                     
 
<source lang="vb">If SDB.Objects("MyWindowRef") Is Nothing Then    ' If the object isn't in collection yet...
 
<source lang="vb">If SDB.Objects("MyWindowRef") Is Nothing Then    ' If the object isn't in collection yet...
 
   Set SDB.Objects("MyWindowRef") = MyWindow      ' ... add it to the collection (using Set for objects)...
 
   Set SDB.Objects("MyWindowRef") = MyWindow      ' ... add it to the collection (using Set for objects)...
Line 18: Line 18:
  
 
SDB.Objects("MyWindowRef") = Nothing            '  ... and now remove it from the collection.</source>
 
SDB.Objects("MyWindowRef") = Nothing            '  ... and now remove it from the collection.</source>
 +
 +
=== Example JScript code ===
 +
 +
<source lang="javascript">
 +
if (!SDB.Objects('MyWindowRef')) { // If the object isn't in collection yet...
 +
  SDB.Objects('MyWindowRef') = my_window; // add it to the collection.
 +
}
 +
</source>
 +
 +
To release the object from global storage, you cannot call <tt>delete SDB.Objects('MyWindowRef')</tt> nor do <tt>SDB.Objects('MyWindowRef') = null</tt>. Best way is to reassign the storage key with empty JScript object. Later on, if you want to access the object from global storage, you should additionally check for the empty object presence as shown below.
 +
 +
<source lang="javascript">
 +
var ref = SDB.Objects('MyWindowRef'); // Get the reference...
 +
if (!ref || (ref && !!ref.__empty)) { // If the object isn't in collection yet or there is the empty object instead...
 +
  SDB.Objects('MyWindowRef') = my_window; // add it to the collection.
 +
}
 +
 +
// Some code here
 +
 +
SDB.Objects('MyWindowRef') = {'__empty': true}; // And now remove it from the collection by replacing with special empty object.
 +
</source>
  
 
[[Category:Scripting|{{PAGENAME}}]]
 
[[Category:Scripting|{{PAGENAME}}]]

Revision as of 17:03, 15 April 2013

CoClass SDBApplication, Interface ISDBApplication

Property Get/Let Objects(Name As String) As Object


Parameters

Name Type Description
Name String An identifier for object storage.


Property description

A collection for temporary storage of any type of object during MediaMonkey running time. For example if a window is created by script that should remain visible while the script isn't running, the window object can be put into this collection in order to keep a reference to it. The keys of this collection are strings, the values can be only objects.

Example VBScript code

If SDB.Objects("MyWindowRef") Is Nothing Then    ' If the object isn't in collection yet...
  Set SDB.Objects("MyWindowRef") = MyWindow      ' ... add it to the collection (using Set for objects)...
End If

' Some code here

SDB.Objects("MyWindowRef") = Nothing             '  ... and now remove it from the collection.

Example JScript code

if (!SDB.Objects('MyWindowRef')) { // If the object isn't in collection yet...
  SDB.Objects('MyWindowRef') = my_window; // add it to the collection.
}

To release the object from global storage, you cannot call delete SDB.Objects('MyWindowRef') nor do SDB.Objects('MyWindowRef') = null. Best way is to reassign the storage key with empty JScript object. Later on, if you want to access the object from global storage, you should additionally check for the empty object presence as shown below.

var ref = SDB.Objects('MyWindowRef'); // Get the reference...
if (!ref || (ref && !!ref.__empty)) { // If the object isn't in collection yet or there is the empty object instead...
  SDB.Objects('MyWindowRef') = my_window; // add it to the collection.
}

// Some code here

SDB.Objects('MyWindowRef') = {'__empty': true}; // And now remove it from the collection by replacing with special empty object.