Copy and DeepCopy (Record functions): Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (Created page with "{{Template:Recordset:DeepCopy subtitle}} <var>DeepCopy</var> is a function that returns an exact copy of the method <var>Recordset</var> object. It is identical to the <var>Reco...")
 
mNo edit summary
 
(11 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{Template:Recordset:DeepCopy subtitle}}
{{Template:Record:Copy and DeepCopy subtitle}}


<var>DeepCopy</var> is a function that returns an exact copy of the method <var>Recordset</var> object. It is identical to the <var>Recordset</var> <var>[[Copy (Recordset function)|Copy]]</var> method. <var>Recordset</var> objects are always copyable and "deep-copyable" (as these terms are described in [[Copying objects#The Object class copy methods|"The Object class copy methods"]]).
<var>Copy</var> is a function that makes an exact copy of a <var>Record</var> object.
<var>DeepCopy</var> performs the identical function. <var>Record</var> objects are always copyable and "deep-copyable" (as these terms are described in [[Copying objects#The Object class copy methods|"The Object class copy methods"]]).


==Syntax==
==Syntax==
{{Template:Recordset:DeepCopy syntax}}
{{Template:Record:DeepCopy syntax}}
 
===Syntax terms===
===Syntax terms===
<table class="syntaxTable">
<table class="syntaxTable">
<tr><th>%newSet</th>
<tr><th>%outRecord</th>
<td>A <var>Recordset</var> object created by this method that contains a copy of the method object.
<td>A <var>Record</var> object created by this method that contains a copy of the method object.</td></tr>
</td></tr>
 
<tr><th>%recSet</th>
<tr><th>record</th>
<td>A <var>Recordset</var> object variable. The variable can be null, in which case the output object will also be null.
<td>A <var>Record</var> object variable. The variable can be <var>Null</var>, in which case the output object will also be <var>Null</var>.</td></tr>
</td></tr>
 
<tr><th>lockstrength</th>
<tr><th>lockstrength</th>
<td>A value of the <var>LockStrength</var> enumeration that is the lock strength to give to the instantiated <var>Recordset</var> object. Options are: <var>None</var>, <var>Share</var>, or <var>Exclusive</var>, as described in [[New (Recordset constructor)|"New (Recordset constructor)"]]. This is an optional parameter, and it defaults to the lock strength of the method object. Specifying a stronger <var>LockStrength</var> than the method object's lock strength is invalid and results in request cancellation.
<td>A value of the <var>LockStrength</var> enumeration that is the lock strength to give to the instantiated <var>Record</var> object. Options are: <var>None</var>, <var>Share</var>, or <var>Exclusive</var>, as described in [[New (Recordset constructor)|"New (Recordset constructor)"]]. This is an optional parameter, and it defaults to the lock strength of the method object. </td></tr>
</td></tr>
 
<tr><th><var>LoopLockStrength</var></th>
<tr><th><var>LoopLockStrength</var></th>
<td>The lock strength to be used for loops on the copied <var>Recordset</var>. This is an optional, [[Notation conventions for methods#Named parameters|name required]], parameter, and it defaults to the <var>LoopLockStrength</var> of the method object <var>Recordset</var>. This parameter is only available in <var class="product">Sirius Mods</var> 7.0 and later. See [[Recordset class#LoopLockStrength for Recordsets|"LoopLockStrength for Recordsets"]].
<td>The lock strength to be used for loops on the copied <var>Record</var>. This is an optional, [[Notation conventions for methods#Named parameters|name required]], parameter, and it defaults to the <var>LoopLockStrength</var> of the method object <var>Record</var>. See [[Record class#LoopLockStrength for Records|"LoopLockStrength for Records"]]. </td></tr>
 
</table>
</td></tr></table>


==Usage notes==
==Usage notes==
<ul>
<ul>
<li>You can only create a copy of lock strength less than
<li>Before <var class="product">Sirius Mods</var> 7.0,
or equal to the original, so <var>Copy</var> needs to acquire no locks
<var>Copy</var> did not allow setting of the target lock strength.
that the user does not already hold.
So, before <var class="product">Sirius Mods</var> 7.0,
Therefore, <var>Copy</var> cannot produce a record locking conflict.
to make a <var>Record</var> object copy with a different lock strength, the <var>New</var> or
<li>Specifying a lock strength greater than the lock strength of the method
<var>CurrentRecord</var> (inside a <var>For</var> record loop) methods had to be used.
object is a request-cancelling error.
</ul>
==Example==
 
In the following example, a base record set is created, copied, then added to:
<p class="code"> begin
  %baseStooges is object recordset in file glwproc
  %copyStooges is object recordset in file glwproc
  %curleyStooge is object recordset in file glwproc


  fd to %baseStooges name = 'MOE' or name = 'LARRY'
<li>Since a <var>Record</var> object and its copy reference the same underlying
      end find
record, there generally isn't a good reason to make a copy of a <var>Record</var>
  text
object &mdash; it makes more sense to just assign the reference to the
      ------
<var>Record</var> object.
      The names of the %baseStooges are:
The copy functionality for <var>Records</var> is mainly for the support of <var>DeepCopy</var>
  end text
of <var>Record</var> objects, the main value of which is to facilitate passing of these objects to and
  fr in %baseStooges
from [[Daemon class|daemons]].
      text
        {name}
      end text
  end for


  %copyStooges = %baseStooges:copy
<li>The following example illustrates the use of the <var>DeepCopy</var> function:
  fd to %curleyStooge with name = 'CURLEY'
<p class="code">%firstRec       is object record in file geeks
       end find
%currentRec    is object record in file geeks
  %copyStooges:addRecordset( %curleyStooge )
...
  text
%currentRec = %firstRec:deepcopy
      ------
      The names of the {%copyStooges:Count} %copyStooges are:
  end text
  fr in %copyStooges
      text
        {name}
      end text
  end for
end
</p>
</p>
</ul>


The example results follow:
<p class="output"> ------
The names of the %baseStooges are:
MOE
LARRY
------
The names of the 3 %copyStooges are:
MOE
LARRY
CURLEY
</p>
==See also==
==See also==
{{Template:Recordset:DeepCopy footer}}
{{Template:Record:Copy and DeepCopy footer}}

Latest revision as of 17:06, 7 November 2012

Copy or deep copy this Record object (Record class)


Copy is a function that makes an exact copy of a Record object. DeepCopy performs the identical function. Record objects are always copyable and "deep-copyable" (as these terms are described in "The Object class copy methods").

Syntax

%outRecord = record:DeepCopy[( [lockStrength], - [LoopLockStrength= lockStrength])]

Syntax terms

%outRecord A Record object created by this method that contains a copy of the method object.
record A Record object variable. The variable can be Null, in which case the output object will also be Null.
lockstrength A value of the LockStrength enumeration that is the lock strength to give to the instantiated Record object. Options are: None, Share, or Exclusive, as described in "New (Recordset constructor)". This is an optional parameter, and it defaults to the lock strength of the method object.
LoopLockStrength The lock strength to be used for loops on the copied Record. This is an optional, name required, parameter, and it defaults to the LoopLockStrength of the method object Record. See "LoopLockStrength for Records".

Usage notes

  • Before Sirius Mods 7.0, Copy did not allow setting of the target lock strength. So, before Sirius Mods 7.0, to make a Record object copy with a different lock strength, the New or CurrentRecord (inside a For record loop) methods had to be used.
  • Since a Record object and its copy reference the same underlying record, there generally isn't a good reason to make a copy of a Record object — it makes more sense to just assign the reference to the Record object. The copy functionality for Records is mainly for the support of DeepCopy of Record objects, the main value of which is to facilitate passing of these objects to and from daemons.
  • The following example illustrates the use of the DeepCopy function:

    %firstRec is object record in file geeks %currentRec is object record in file geeks ... %currentRec = %firstRec:deepcopy

See also