SortedRecordset class: Difference between revisions
mNo edit summary |
|||
(11 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
<!-- SortedRecordset class --> | <!-- SortedRecordset class --> | ||
A SortedRecordset object represents an ordered | A <var>SortedRecordset</var> object represents an ordered | ||
set of records, much as a label on a Sort statement does in | set of records, much as a label on a <var>Sort</var> statement does in | ||
traditional User Language. | traditional <var class="product">User Language</var>. | ||
Like the other file-oriented objects, you use the following syntax | Like the other file-oriented objects, you use the following syntax | ||
to declare a SortedRecordset object: | to declare a <var>SortedRecordset</var> object: | ||
<p class="code"> %srs is object SortedRecordset - | <p class="code">%srs is object SortedRecordset - | ||
In [ File <i>fname</i> ] | |||
[ [ Temp | Perm ] Group <i>gname</i> ] | |||
[ <i>fgname</i> ] | |||
</p> | </p> | ||
For example: | For example: | ||
<p class="code"> | <p class="code">srtStoogesL is object SortedRecordset in file ftpproc | ||
... | |||
%s is object SortedRecordset in foo | |||
... | |||
%sk is object SortedRecordset in temp group foo | |||
... | |||
%skp is object SortedRecordset in perm group foo | |||
</p> | </p> | ||
==Instantiating SortedRecordset objects== | ==Instantiating SortedRecordset objects== | ||
Prior to version 7.6 of the <var class="product">Sirius Mods</var>, the SortedRecordset class | Prior to version 7.6 of the <var class="product">Sirius Mods</var>, the <var>SortedRecordset</var> class | ||
contained no native constructor method, and | contained no native constructor method, and | ||
the way to instantiate a SortedRecordset object is to | the way to instantiate a <var>SortedRecordset</var> object is to | ||
make it the target of a Sort statement. | make it the target of a <var>Sort</var> statement. | ||
In version 7.6, the RecordsetCursor New method was added, | In version 7.6, the <var>RecordsetCursor</var> <var>[[New (RecordsetCursor constructor)|New]]</var> method was added, | ||
primarily to enable the creation of extension classes of | primarily to enable the creation of extension classes of | ||
the SortedRecordset class, which the Sort statement constructor | the <var>SortedRecordset</var> class, which the <var>Sort</var> statement constructor cannot do. | ||
cannot do. | |||
Instantiation by the New method and by Sort statement is described below. | Instantiation by the <var>New</var> method and by <var>Sort</var> statement is described below. | ||
<ul> | <ul> | ||
<li>A SortedRecordset <code>New</code> constructor has no parameters and simply | <li>A <var>SortedRecordset</var> <code>New</code> constructor has no parameters and simply | ||
instantiates an empty instance of its class. | instantiates an empty instance of its class. | ||
For example: | For example: | ||
<p class="code"> %srs is object sortedRecordset in | <p class="code">%srs is object sortedRecordset in sordId | ||
... | |||
%srs = new | |||
</p> | </p> | ||
Such a new instance is not of significant value, and in most cases, | Such a new instance is not of significant value, and in most cases, | ||
the best way to instantiate a SortedRecordset instance is to | the best way to instantiate a <var>SortedRecordset</var> instance is to | ||
use the Sort statement construction described below. | use the <var>Sort</var> statement construction described below. | ||
As indicated earlier, however, the New constructor does | As indicated earlier, however, the <var>New</var> constructor does | ||
enable the creation of an extension class of the SortedRecordset class, | enable the creation of an extension class of the <var>SortedRecordset</var> class, | ||
an example of which is shown in | an example of which is shown in <var>[[New (SortedRecordset constructor)|New]]</var>. | ||
<li>Much like a Recordset object, | <li>Much like a <var>[[Recordset class|Recordset]]</var> object, | ||
you can instantiate a SortedRecordset object by | you can instantiate a <var>SortedRecordset</var> object by | ||
making it the target of a Sort statement. | making it the target of a <var>Sort</var> statement. | ||
For example: | For example: | ||
<p class="code"> Sort Records In %recset To %sortedrecset | <p class="code">Sort Records In %recset To %sortedrecset By Name and Testkey | ||
</p> | </p> | ||
The Sort Records and Sort Record Keys statements may instantiate | The <var>Sort Records</var> and <var>Sort Record Keys</var> statements may instantiate | ||
SortedRecordset objects, and they also may specify the | <var>SortedRecordset</var> objects, and they also may specify the | ||
number of records sorted (Sort n Records, | number of records sorted (<code>Sort n Records</code>, | ||
Sort n Record Keys). | <code>Sort n Record Keys</code>). | ||
The In clause of an instantiating Sort statement may reference a | The <var>In</var> clause of an instantiating <var>Sort</var> statement may reference a | ||
Recordset object or a Find statement label. | <var>Recordset</var> object or a <var>Find</var> statement label. | ||
In addition, an On list phrase is supported with both Sort statement forms. | In addition, an <code>On list</code> phrase is supported with both <var>Sort</var> statement forms. | ||
This permits easy conversion of old applications: | This permits easy conversion of old applications: | ||
you can sort any existing found set or list and instantiate a | you can sort any existing found set or list and instantiate a | ||
SortedRecordset object. | <var>SortedRecordset</var> object. | ||
The revised syntax of the Sort statement is as follows, | The revised syntax of the <var>Sort</var> statement is as follows, | ||
where any of the Sort | where any of the <var>Sort</var> "phrases" combined with any <var>In</var> or <var>On</var> phrase may | ||
instantiate a SortedRecordset object. | instantiate a <var>SortedRecordset</var> object. | ||
Note that a By phrase is also required. | Note that a <var>By</var> phrase is also required. | ||
<p class="code"> {Sort Records } {In label } [To %srtrset] By ... | <p class="code">{Sort Records } {In <i>label</i> } [To <i>%srtrset</i>] By ... | ||
{Sort Record Keys } {In <i>%recset</i>} | |||
{Sort <i>n</i> Records } {On <i>list</i> } | |||
{Sort <i>n</i> Record Keys} | |||
</p> | </p> | ||
Here are some examples: | Here are some examples: | ||
<p class="code"> sort records on lll to %srs by testkey | <p class="code">sort records on lll to %srs by testkey | ||
... | ... | ||
srt1: sort records in %rset by testkey | |||
... | ... | ||
sort records in %rs to %srs by name | |||
... | ... | ||
sort records in a to %s by testkey | |||
... | ... | ||
sort 2 records in %r to %s by name | |||
... | ... | ||
sort 2 record keys in %r to %sk by name value descending | |||
</p> | </p> | ||
While you may still place a label on the Sort statement (and | While you may still place a label on the <var>Sort</var> statement (and | ||
use it as a Jump To target), you may not refer by label to an | use it as a <var>Jump To</var> target), you may not refer by label to an | ||
instantiated SortedRecordset object that is the | instantiated <var>SortedRecordset</var> object that is the | ||
output of a Sort statement. | output of a <var>Sort</var> statement. | ||
You must refer to the | You must refer to the | ||
SortedRecordset object variable. | <var>SortedRecordset</var> object variable. | ||
This is described in the next section. | This is described in the next section. | ||
</ul> | </ul> | ||
==Referencing the records in an object instance== | ==Referencing the records in an object instance== | ||
You loop on a SortedRecordset object with the identical For | You loop on a <var>SortedRecordset</var> object with the identical <var>For | ||
Each Record syntax that you use to loop on a regular Recordset object: | Each Record</var> syntax that you use to loop on a regular <var>Recordset</var> object: | ||
<p class="code"> For Each Record In %srs | <p class="code">For Each Record In %srs | ||
... | ... | ||
Fr In %srs | |||
</p> | </p> | ||
As with Recordset objects, the <code>In</code> is required. | As with <var>Recordset</var> objects, the <code>In</code> is required. | ||
==Freeing a sorted record set== | ==Freeing a sorted record set== | ||
Release Records In may refer to a SortedRecordset object instance, | <var>Release Records In</var> may refer to a <var>SortedRecordset</var> object instance, | ||
as well as to a Recordset object instance. | as well as to a <var>Recordset</var> object instance. | ||
A SortedRecordset | A <var>SortedRecordset</var> instance specified on a <var>Release</var> statement is discarded, and all CCATEMP | ||
instance specified on a Release statement is discarded, and all CCATEMP | |||
pages associated with it are freed. | pages associated with it are freed. | ||
In addition to the Release statement to discard a SortedRecordset object, | In addition to the <var>Release</var> statement to discard a <var>SortedRecordset</var> object, | ||
you may also use the Discard function (as in, <code>%srecs:discard</code>). | you may also use the <var>[[Object_variables#Discarding_objects|Discard]]</var> function (as in, <code>%srecs:discard</code>). | ||
==SortedRecordset example== | ==SortedRecordset example== | ||
The following short example demonstrates the basic operations | The following short example demonstrates the basic operations | ||
with SortedRecordset objects: | with <var>SortedRecordset</var> objects: | ||
<p class="code"> begin | <p class="code">begin | ||
%recs is object recordSet in file ftptest | |||
%srecs is object sortedRecordset in file ftptest | |||
* create the recordset | |||
fd to %recs | |||
end find | |||
* sort them | |||
sort records in %recs to %srecs by testkey | |||
print %srecs:count | |||
* loop on the sorted version | |||
fr in %srecs | |||
pai | |||
end for | |||
* free the set objects | |||
release records in %recs | |||
release records in %srecs | |||
end | |||
</p> | </p> | ||
==List of SortedRecordset methods== | |||
The [[List of SortedRecordset methods|"List of SortedRecordset methods"]] shows all the class methods. | |||
[[Category:System classes]] | [[Category:System classes]] |
Latest revision as of 21:32, 9 November 2012
A SortedRecordset object represents an ordered set of records, much as a label on a Sort statement does in traditional User Language.
Like the other file-oriented objects, you use the following syntax to declare a SortedRecordset object:
%srs is object SortedRecordset - In [ File fname ] [ [ Temp | Perm ] Group gname ] [ fgname ]
For example:
srtStoogesL is object SortedRecordset in file ftpproc ... %s is object SortedRecordset in foo ... %sk is object SortedRecordset in temp group foo ... %skp is object SortedRecordset in perm group foo
Instantiating SortedRecordset objects
Prior to version 7.6 of the Sirius Mods, the SortedRecordset class contained no native constructor method, and the way to instantiate a SortedRecordset object is to make it the target of a Sort statement. In version 7.6, the RecordsetCursor New method was added, primarily to enable the creation of extension classes of the SortedRecordset class, which the Sort statement constructor cannot do.
Instantiation by the New method and by Sort statement is described below.
- A SortedRecordset
New
constructor has no parameters and simply instantiates an empty instance of its class. For example:%srs is object sortedRecordset in sordId ... %srs = new
Such a new instance is not of significant value, and in most cases, the best way to instantiate a SortedRecordset instance is to use the Sort statement construction described below. As indicated earlier, however, the New constructor does enable the creation of an extension class of the SortedRecordset class, an example of which is shown in New.
- Much like a Recordset object,
you can instantiate a SortedRecordset object by
making it the target of a Sort statement.
For example:
Sort Records In %recset To %sortedrecset By Name and Testkey
The Sort Records and Sort Record Keys statements may instantiate SortedRecordset objects, and they also may specify the number of records sorted (
Sort n Records
,Sort n Record Keys
).The In clause of an instantiating Sort statement may reference a Recordset object or a Find statement label. In addition, an
On list
phrase is supported with both Sort statement forms. This permits easy conversion of old applications: you can sort any existing found set or list and instantiate a SortedRecordset object.The revised syntax of the Sort statement is as follows, where any of the Sort "phrases" combined with any In or On phrase may instantiate a SortedRecordset object. Note that a By phrase is also required.
{Sort Records } {In label } [To %srtrset] By ... {Sort Record Keys } {In %recset} {Sort n Records } {On list } {Sort n Record Keys}
Here are some examples:
sort records on lll to %srs by testkey ... srt1: sort records in %rset by testkey ... sort records in %rs to %srs by name ... sort records in a to %s by testkey ... sort 2 records in %r to %s by name ... sort 2 record keys in %r to %sk by name value descending
While you may still place a label on the Sort statement (and use it as a Jump To target), you may not refer by label to an instantiated SortedRecordset object that is the output of a Sort statement. You must refer to the SortedRecordset object variable. This is described in the next section.
Referencing the records in an object instance
You loop on a SortedRecordset object with the identical For Each Record syntax that you use to loop on a regular Recordset object:
For Each Record In %srs ... Fr In %srs
As with Recordset objects, the In
is required.
Freeing a sorted record set
Release Records In may refer to a SortedRecordset object instance, as well as to a Recordset object instance. A SortedRecordset instance specified on a Release statement is discarded, and all CCATEMP pages associated with it are freed.
In addition to the Release statement to discard a SortedRecordset object,
you may also use the Discard function (as in, %srecs:discard
).
SortedRecordset example
The following short example demonstrates the basic operations with SortedRecordset objects:
begin %recs is object recordSet in file ftptest %srecs is object sortedRecordset in file ftptest * create the recordset fd to %recs end find * sort them sort records in %recs to %srecs by testkey print %srecs:count * loop on the sorted version fr in %srecs pai end for * free the set objects release records in %recs release records in %srecs end
List of SortedRecordset methods
The "List of SortedRecordset methods" shows all the class methods.