ISDBApplication::Objects: Difference between revisions

From MediaMonkey Wiki
Jump to navigation Jump to search
m (Corrected the example code for VBScript)
 
(3 intermediate revisions by the same user not shown)
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===                     
Some MediaMonkey objects are destroyed when last reference to them is deleted (such as [[SDBUIForm|form]] or [[SDBProgress|progress bar]]). In JScript there may be a delay between last reference removal and object disposal. In this case you might want to consider calling [http://msdn.microsoft.com/en-us/library/ff955348%28v=vs.85%29.aspx CollectGarbage()] method to tell the interpret to dispose objects right now.
 
===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 20:


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>, but you have to reassing the value. For example with <tt>null</tt>. However note that the object '''may''' be destroyed when there are '''no''' references left (thus SDB.Objects was the last one holding the object). If you want to destroy the object right now, consider calling <tt>CollectGarbage()</tt> method.
<source lang="javascript">
SDB.Objects('MyWindowRef') = null; // Release instance from the collection.
CollectGarbage(); // Consider calling garbage collector when needing object disposal right now.
</source>


[[Category:Scripting|{{PAGENAME}}]]
[[Category:Scripting|{{PAGENAME}}]]

Latest revision as of 23:03, 25 November 2014

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.

Some MediaMonkey objects are destroyed when last reference to them is deleted (such as form or progress bar). In JScript there may be a delay between last reference removal and object disposal. In this case you might want to consider calling CollectGarbage() method to tell the interpret to dispose objects right now.

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'), but you have to reassing the value. For example with null. However note that the object may be destroyed when there are no references left (thus SDB.Objects was the last one holding the object). If you want to destroy the object right now, consider calling CollectGarbage() method.

SDB.Objects('MyWindowRef') = null; // Release instance from the collection.
CollectGarbage(); // Consider calling garbage collector when needing object disposal right now.