Item (NamedArraylist property): Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (1 revision)
mNo edit summary
 
(14 intermediate revisions by 5 users not shown)
Line 1: Line 1:
<span style="font-size:120%; color:black"><b><section begin=dpl_desc/>Value of named item<section end=dpl_desc/></b></span>
{{Template:NamedArraylist:Item subtitle}}
[[Category:NamedArraylist methods|Item property]]
<!--DPL?? Category:NamedArraylist methods|Item property: Value of named item-->
<!-- This is very close to the same method's page for these classes:
<p>
      FloatNamedArraylist
Item is a member of the [[NamedArraylist class]].
      UnicodeNamedArraylist
</p>
    Many changes should be reflected to all three method's pages -->
 
This ReadWrite property returns or sets the value of the item that has the
<var>Item</var> is a ReadWrite property which returns or sets the value of the item that has the given name in the <var>NamedArraylist</var>.
given name in the NamedArraylist.
 
For additional comments about the <var>Item</var> method in collections, see [[Collections#Coding considerations for collections|"Coding considerations for collections"]].
For additional comments about the Item method in collections,
see [[Collections#Coding considerations for collections|Coding considerations for collections]].
==Syntax==
==Syntax==
<p class="code">%item = %namrayl:Item(name)
{{Template:NamedArraylist:Item syntax}}
 
===Syntax terms===
%namrayl:Item(name) = %item
<!-- This is very close to the same method's page for these classes:
      FloatNamedArraylist
      UnicodeNamedArraylist
    Many changes should be reflected to all three method's pages -->
<table class="syntaxTable">
<tr><th>%currentItem</th>
<td>A variable of the same type as specified on the <var class="term">nal</var> declaration to contain the value of the specified <var class="term">nal</var> item.</td></tr>
<tr><th>nal</th>
<td>A <var>NamedArraylist</var> object.</td></tr>
<tr><th>string</th>
<td>A string that serves as a subscript to identify a <var class="term">nal</var> item.</td></tr>
<tr><th>newItem</th>
<td>A value of the same type as specified on the <var class="term">nal</var> declaration to be assigned to the specified <var class="term">nal</var> item. </td></tr>
</table>
==Usage notes==
<!-- This is very close to the same method's page for these classes:
      FloatNamedArraylist
      UnicodeNamedArraylist
    Many changes should be reflected to all three method's pages -->
<ul>
<li>The <var>Item</var> keyword is not required.  For example, in the first of the [[NamedArraylist class#Examples|"Examples"]] on the <var>NamedArraylist</var> class page, the following statement:
<p class="code">%alist('Idle') = 'Eric'</p>
is equivalent to:
<p class="code">%alist:Item('Idle') = 'Eric'
</p>
</p>
===Syntax Terms===
<li>If the <var>Item</var> property is being set and there is already an item on the <var>NamedArraylist</var> that has the specified name, that item is replaced. If the <var>Item</var> property is being set and there is no item on the <var>NamedArraylist</var> that has the indicated name, the item is added.
<dl>
<li>If the <var>Item</var> property is being retrieved and there is no item on the <var>NamedArraylist</var> that has the indicat ed name, the result is one of the following actions:
<dt><i>%item</i>
<dd>A variable of the same
type as specified on the ''%namrayl'' declaration
to contain the value of the specified ''%namrayl'' item.
Or a variable or value of the same
type as specified on the ''%namrayl'' declaration
to be assigned to the specified ''%namrayl'' item.
<dt><i>%namrayl</i>
<dd>A NamedArraylist object.
<dt><i>name</i>
<dd>A string that serves as a subscript to identify a ''%namrayl'' item.
 
</dl>
==Usage Notes==
<ul>
<ul>
<li>If the Item property is being set and there is already an item
<li>If the <var>[[UseDefault (NamedArraylist property)|UseDefault]]</var> property value is <code>False</code>:
on the NamedArraylist that has the specified name, that item is replaced.
 
If the Item property is being set and there is no item on the NamedArraylist
that has the indicated name, the item is added.
 
If the Item property is being retrieved and there is no item on the NamedArraylist
that has the indicated name, the result is one of the following actions:
<ul>
<ul>
<li>The request is cancelled if the [[UseDefault (NamedArraylist property)|UseDefault]]
<li>Under <var>Sirius Mods</var> version 8.0 and later an <var>[[ItemNotPresent class|ItemNotPresent exception]]</var> is thrown.
property value is <tt>False</tt>.
<li>Under <var>Sirius Mods</var> version 7.9 and earlier the request is cancelled.
<li>The [[Default (NamedArraylist property)|Default]] value is returned if the
</ul>
UseDefault property is <tt>True</tt>.
<li>The <var>[[Default (NamedArraylist property)|Default]]</var> value is returned if the <var>UseDefault</var> property is <code>True</code>.
</ul>
</ul>
<li>The <tt>Item</tt> keyword is not required.
Regardless of the value of <var>UseDefault</var>, the presence of the item with the indicated name can be checked using the <var>[[Number (NamedArraylist function)|Number]]</var> function, for example:
For example, in the request at the start of the
<p class="code">%num = %myLis:number(%key)
[[NamedArraylist class]], <tt>%alist('Idle') = 'Eric'</tt>, for instance,
if %num then %name = %myLis:[[ItemByNumber (NamedArraylist property)|itemByNumber]](%num)
is equivalent to:
...
<p class="code">%alist:Item('Idle') = 'Eric'
</p>
</p>
<li>As shown in the example at the start of the [[NamedArraylist class]],
<li>As shown in the first of the <var>NamedArraylist</var> [[NamedArraylist class#Examples|"Examples"]],
NamedArraylist items are ordered alphabetically by their names.
<var>NamedArraylist</var> items are ordered alphabetically by their names.
Accordingly, the Item method takes a ''name'' argument.
</ul>
The ItemByNumber method, described below,
lets you retrieve or set an item using its item number.
==See also==
<!-- This is very close to the same method's page for these classes:
      FloatNamedArraylist
      UnicodeNamedArraylist
    Many changes should be reflected to all three method's pages -->
<ul><li>The <var>[[ItemByNumber_(GenericNamedArraylist_property)|ItemByNumber]]</var> property lets you retrieve or set an item using the item's ordinal number.
<li>The <var>[[NameByNumber (NamedArraylist function)|NameByNumber]]</var> function lets you retrieve an item's name using the item's ordinal number.
<li>The <var>[[Number (NamedArraylist function)|Number]]</var> function lets you retrieve an item's ordinal number using the item's name; it can be useful for determining whether an item exists for a specified name.
</ul>
</ul>
{{Template:NamedArraylist:Item footer}}

Latest revision as of 16:41, 5 August 2012

Value of named item (NamedArraylist class)


Item is a ReadWrite property which returns or sets the value of the item that has the given name in the NamedArraylist.

For additional comments about the Item method in collections, see "Coding considerations for collections".

Syntax

%currentItem = nal:Item( string) nal:Item( string) = newItem Throws ItemNotPresent

Syntax terms

%currentItem A variable of the same type as specified on the nal declaration to contain the value of the specified nal item.
nal A NamedArraylist object.
string A string that serves as a subscript to identify a nal item.
newItem A value of the same type as specified on the nal declaration to be assigned to the specified nal item.

Usage notes

  • The Item keyword is not required. For example, in the first of the "Examples" on the NamedArraylist class page, the following statement:

    %alist('Idle') = 'Eric'

    is equivalent to:

    %alist:Item('Idle') = 'Eric'

  • If the Item property is being set and there is already an item on the NamedArraylist that has the specified name, that item is replaced. If the Item property is being set and there is no item on the NamedArraylist that has the indicated name, the item is added.
  • If the Item property is being retrieved and there is no item on the NamedArraylist that has the indicat ed name, the result is one of the following actions:
    • If the UseDefault property value is False:
      • Under Sirius Mods version 8.0 and later an ItemNotPresent exception is thrown.
      • Under Sirius Mods version 7.9 and earlier the request is cancelled.
    • The Default value is returned if the UseDefault property is True.

    Regardless of the value of UseDefault, the presence of the item with the indicated name can be checked using the Number function, for example:

    %num = %myLis:number(%key) if %num then %name = %myLis:itemByNumber(%num) ...

  • As shown in the first of the NamedArraylist "Examples", NamedArraylist items are ordered alphabetically by their names.

See also

  • The ItemByNumber property lets you retrieve or set an item using the item's ordinal number.
  • The NameByNumber function lets you retrieve an item's name using the item's ordinal number.
  • The Number function lets you retrieve an item's ordinal number using the item's name; it can be useful for determining whether an item exists for a specified name.