ISDBApplication::Progress: Difference between revisions
No edit summary |
(Added note about ISDBProgress::Terminate property and modified example to take care of Terminate value) |
||
(3 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
{{MethodDeclaration|SDBApplication|ISDBApplication|Property Get Progress As ISDBProgress}} | {{MethodDeclaration|SDBApplication|ISDBApplication|Property Get Progress As [[SDBProgress#ISDBProgress objects|ISDBProgress]]}} | ||
===Property description=== | ===Property description=== | ||
Returns [[SDBProgress]] object. It is also initialized and shown this way. In order to further modify the progress bar, see SDBProgress properties. | Returns [[SDBProgress]] object. It is also initialized and shown this way. In order to further modify the progress bar, see [[SDBProgress]] properties. | ||
Progress operation can be cancelled by a user. MediaMonkey then sets value of [[ISDBProgress::Terminate]] property to <tt>TRUE</tt>. Developers are encouraged to periodically check this value (mainly in loops) and terminate the action as soon as possible. | |||
===Example code=== | ===Example code=== | ||
<source lang="vb">Dim Progress | <source lang="vb"> | ||
' Assume variable list exists | |||
Dim Progress | |||
Set Progress = SDB.Progress | Set Progress = SDB.Progress | ||
Progress.Text = SDB.Localize("Exporting...") | Progress.Text = SDB.Localize("Exporting...") | ||
Progress.MaxValue = list. | Progress.MaxValue = list.Count | ||
For i=0 to list.Count-1 | |||
'... some code here | '... some code here | ||
Progress.Value = i+1 | Progress.Value = i+1 | ||
If Progress.Terminate Then | |||
' User cancelled | |||
Exit For | |||
End If | |||
Next | |||
</source> | |||
===Example: Persistent progress bar=== | |||
Progress bar is shown when is instantied by the script, and is removed from window when no reference to its instance remains in memory. | |||
However, we can keep one reference to the bar inside [[ISDBApplication::Objects|SDB.Objects]] storage. This prevents the progress bar from being destroyed by garbage collector and thus it remains visible. | |||
<source lang="javascript"> | |||
// Example code in JavaScript: | |||
function create_persistent_bar() { | |||
var bar = SDB.Progress; | |||
bar.Text = 'This progress bar remains visible.'; | |||
SDB.Objects('MyProgressBar') = bar; // keep one reference to the progress bar in the global storage | |||
} | |||
</source> | |||
'''Removing persistent progress bar'''<br /> | |||
Progress bar is removed after no variables are pointing to the object. So overwriting the reference to the progress bar inside [[ISDBApplication::Objects|SDB.Objects]] with <tt>null</tt>/<tt>Nothing</tt> causes the progress bar dissapear. However, scripting engine does perform garbage collection only from time to time, so we need to call garbage collector explicitly or wait few seconds till progress bar disappears. | |||
<source lang="javascript"> | |||
// Example code in JavaScript: | |||
function remove_persistent_bar() { | |||
SDB.Objects('MyProgressBar') = null; // Unset the reference to progress bar instance. | |||
CollectGarbage(); // This undocumented JScript function runs GC instantly and removes the progress bar. | |||
} | |||
</source> | |||
[[Category:Scripting|{{PAGENAME}}]] | [[Category:Scripting|{{PAGENAME}}]] |
Latest revision as of 19:07, 20 April 2013
CoClass SDBApplication, Interface ISDBApplication
Property Get Progress As ISDBProgress
Property description
Returns SDBProgress object. It is also initialized and shown this way. In order to further modify the progress bar, see SDBProgress properties.
Progress operation can be cancelled by a user. MediaMonkey then sets value of ISDBProgress::Terminate property to TRUE. Developers are encouraged to periodically check this value (mainly in loops) and terminate the action as soon as possible.
Example code
' Assume variable list exists
Dim Progress
Set Progress = SDB.Progress
Progress.Text = SDB.Localize("Exporting...")
Progress.MaxValue = list.Count
For i=0 to list.Count-1
'... some code here
Progress.Value = i+1
If Progress.Terminate Then
' User cancelled
Exit For
End If
Next
Example: Persistent progress bar
Progress bar is shown when is instantied by the script, and is removed from window when no reference to its instance remains in memory. However, we can keep one reference to the bar inside SDB.Objects storage. This prevents the progress bar from being destroyed by garbage collector and thus it remains visible.
// Example code in JavaScript:
function create_persistent_bar() {
var bar = SDB.Progress;
bar.Text = 'This progress bar remains visible.';
SDB.Objects('MyProgressBar') = bar; // keep one reference to the progress bar in the global storage
}
Removing persistent progress bar
Progress bar is removed after no variables are pointing to the object. So overwriting the reference to the progress bar inside SDB.Objects with null/Nothing causes the progress bar dissapear. However, scripting engine does perform garbage collection only from time to time, so we need to call garbage collector explicitly or wait few seconds till progress bar disappears.
// Example code in JavaScript:
function remove_persistent_bar() {
SDB.Objects('MyProgressBar') = null; // Unset the reference to progress bar instance.
CollectGarbage(); // This undocumented JScript function runs GC instantly and removes the progress bar.
}