SetObject (System function): Difference between revisions
m (1 revision) |
m (1 revision) |
||
Line 9: | Line 9: | ||
<p>All other errors result in request cancellation.</p></td></tr> | <p>All other errors result in request cancellation.</p></td></tr> | ||
<tr><th><var>%(System)</var></th> | <tr><th><var>%(System)</var></th> | ||
<td>The class name in parentheses denotes a [[Notation conventions for methods#Shared methods | <td>The class name in parentheses denotes a [[Notation conventions for methods#Shared methods|shared]] method. <var>SetObject</var> can also be invoked via a <var>[[System_class|System]]</var> object variable, which may be <var>null</var>.</td></tr> | ||
<tr><th>name</th> | <tr><th>name</th> | ||
<td>The string name by which the system-wide object is identified.</td></tr> | <td>The string name by which the system-wide object is identified.</td></tr> |
Revision as of 18:28, 30 November 2011
Set a system-wide object (System class)
SetObject sets a "system-wide object".
Syntax
[%gen =] %(System):SetObject( name, object, [testGen])
Syntax terms
%gen | The new generation number associated with name. This is a positive integer (set to 1 the first time the method succeeds) that increases by one each time the name object is updated. gen is set to 0 if the method encounters a problem or if testGen differs from the current generation number of name.
All other errors result in request cancellation. |
---|---|
%(System) | The class name in parentheses denotes a shared method. SetObject can also be invoked via a System object variable, which may be null. |
name | The string name by which the system-wide object is identified. |
object | The object variable that becomes the current system-wide object. The object referenced by object must be "deep copyable"). |
testGen | An optional argument, this is an integer that is compared to the current generation number of name. If the values differ, SetObject fails to replace %obj, and it returns a 0 value. |
Examples
The following example shows how the generation number can be used to make sure that you do not update an object that someone else updated after you got your copy.
%myObj is object myClass ... retry: %gen = %(system):getObject('FOO', %myObj) ... fiddle with the object * Now try to update it if not %(system):setObject('FOO', %myObj, %gen) then * Someone else changed it, let's see what they did jump to retry end if
In this case, when you try to update FOO
, FOO
's generation is compared with %gen
. If the generation number changed, the SetObject call does not succeed, and 0 is returned.