|
Class Reference
%Library.Routine
|
|
![]() |
|||
Private Storage |
The
The
For example, the following code creates, saves, and compiles a simple Caché routine (note that lines of code start with a space character):
Set routine = ##class(%Routine).%New("MyRoutine.MAC") ; Write lines of code to the routine Do routine.WriteLine("MyRoutine") Do routine.WriteLine("Tag()") Do routine.WriteLine(" Write ""This is my routine"",!") Do routine.WriteLine(" Quit") ; save the routine Do routine.Save() ; compile the routine Do routine.Compile()
|
|
Properties | ||||
---|---|---|---|---|
%Location | AtEnd | Attributes | Generated | Id |
IsModified | LanguageMode | LastModified | LineTerminator | Locked |
Name | Namespace | RoutineName | RoutineType | RoutineVersion |
Size | TimeStamp |
|
True if this routine is generated from something else
The language mode of this routine
Number of times this routines has been locked.
The name (without extension) of the routine associated with this object.This is for backwards compatability only.
Return the namespace this routine is from
The name of the routine.
The type of the routine.
|
Checks to see if the object identified by the ID id exists in the extent.Returns
%Boolean TRUE is it exists, FALSE if it does not.
Returns true (1) if a property of this instance has been modified, otherwise false (0). A TRUE result does not necessarily mean that any property has actually been changed. If %IsModified() returns false then the object has not been modified. There are some situations where we simply cannot efficiently detect a change in value. In these cases we will set the modified status of the property.
This method is somewhat similar to %IsModified but it also checks to see if swizzled references would cause the object to become modified should they be serialized. This works on the assumption that a reference to a persistent object will never be modified if the ID has already been assigned. For references to serial objects, a call to %ObjectModified indicates whether or not the serialized value is different. If the reference to a swizzled object is different from the initial object state then the $$$objModAll macro will already return true. Reference the Set code. Returns true (1) if this instance has been modified, otherwise false (0).
Check if we are allowed to save this routine in this namespace
This function syntax checks INT source code.
Source - source (INT) code; either a single line stored in a variable, or an array where: array(0)=#lines, array(1-n)=source
Errors (byref) - Returned array of errors detected by compiler
LanguageMode - language mode, 0-10 (optional, default 0)
Clear the contents of this Stream from permanent storage. This will remove the permanent stream storage and any temporary stream and initialise the stream to its initial state that it starts in, including removing all the stream attributes.Returns a
%Status value indicating success or failure.
Compile this routine. The qspec is the standard objects qualifiers described in 'Do $system.OBJ.ShowQualifiers()'.
Compile all routines in a namespace.
This method will compile all routines in the current namespace.
Flags Bit string of options to method.
Bit 0 - Suppress syntax error display.
Bit 1 - Suppress output to principal device.
IO Already open device to send the output to. For example, "c:\a.out"
Count (by ref) Number of routines compiled.
Errors (by ref) Number of routines with syntax errors.
Compile all routines in all namespace.
This method will compile all routines in all namespaces. This will not compile routines in SYSTEM defined namespaces.
Flags Bit string of options to method.
Bit 0 - Suppress syntax error display.
Bit 1 - Suppress output to principal device.
IO Already open device to send the output to. For example, "c:\a.out"
Count (by ref) Number of routines compiled.
Errors (by ref) Number of routines with syntax errors.
Delete the routine rtnname. The parameter flag specifies now much to delete. The options are:This returns a %Status code to show if it worked or not. If you pass a name like 'test.mac;*' it will delete all backup versions of this routine. If the routine name which is passed does not exists, the method will return success.
- 0 - Delete entire routine, for a MAC routine this will delete MAC, INT, OBJ. For an INT routine it will delete INT and OBJ, for a INC routine it will only delete the INC, for a BAS routine it will delete the BAS and the OBJ code.
- 1 - Delete just the named routine, for example for a MAC routine it will only delete the MAC and it will leave the INT and OBJ if present.
- 2 - Delete all the source code but leave any OBJ code.
Deprecated method, use%Delete instead. Deletes the stored stream identified by oid. This will not remove the stream attributes of any saved streams, it will just remove the stream data. If you need to clear the attributes as well you will have to callClear on the stream object.
This is a class method which tests if the routine name exists.If name consists of a routine name and an extension, such as INT, MAC, etc. then it will check for this specific routine. If it just contains the routine name it will check if either MAC, INT, or BAS exists.
Write ##class(%Routine).Exists("Test.MAC") Write ##class(%Routine).Exists("Test")
Flush any output in the stream not already saved.
Get the on-disk timestamp for the routine.
Return the timestamp the routine with name was last updated.
Returns the major.minor version number of the Caché compiler that produced the object code for this routine. Returns 0 if there is no object code for the routine.
This is a Get accessor method for theLanguageMode property.
This is a Set accessor method for theLanguageMode property.
This is a Get accessor method for theLastModified property.
This is a Get accessor method for theLineTerminator property.
Lock the current routine
Lock a particular routinename . Iflock is true (the default) then it locks the routine, and if false then it unlocks the routine. If a routine is derived from a class then it will lock the class name in ^oddDEF to prevent another user from attempting to edit the class at the same time this process is editing the routine. If IModeLock is True, then it will unlock the routine with the #I flag so that the node will unlock even if in a transaction.
Move to the end of the stream so the nextWrite will be appended to the end. This allows you to read from a stream, then MoveToEnd() and append new data, where just calling Write after a read will clear the stream before writing new data.Returns a
%Status value indicating success or failure.
This is a Get accessor method for theName property.
This is a Get accessor method for theNamespace property.
Reads up to len characters from the current position in the stream. The current position is advanced by the number of characters read. Upon exit, len is set to the actual number of characters read. If a read occurs when the stream position is at the end of the stream, len will be set to -1 andRead will return a null string ("").You must call
Rewind if you want to read a stream from the beginning again. CallingRead afterWrite implicitly ends theWrite operation and rewinds to the start of the stream.Returns a string up to len characters long. The byref argument sc will return a %Status if any error occurred during the read.
Read a line from the stream. This will look for the line terminator in the stream and once it finds the terminator it will return the string minus the terminator character/s. If it reaches the end of the stream before it finds a terminator it will return the data it has so far, and if you specify a maximum size in len it will only read up to this number of characters. On exit len will contain the actual number of characters read. The byref argument sc will return a %Status if any error occured during the read and the byref argument eol is true if it found the line terminator and false otherwise. So for example you can read in a stream a line at a time and output the results to the current device with:While 'stream.AtEnd { Write stream.ReadLine(,.sc,.eol) If $$$ISERR(sc) { Write "ERROR" Quit } If eol { Write ! } }
Go back to the start of the stream.
This is an instance method which tests if this routine exists (that is, it has been saved to disk).
Fetch returns the next row in the query.
RoutineListFetchRows returns the next FetchCount rows in the query.
This is a Set accessor method for theRoutineName property.
Fetch returns the next row in the query.
RoutineListFetchRows returns the next FetchCount rows in the query.
Save this routine.
Deprecated method, use%Save instead. Saves the temporary copy of the stream data to a persistent location. Note that any locking or transaction handling must be done by the caller.Returns a
%Status value indicating success or failure.
Return the current size of the data stream.
Unlock the current routine
Appends the string data to the stream and advances the current stream position by the number of characters in data.Note that a write operation immediately following a read or rewind will clear out the existing data in the stream.
Returns a
%Status value indicating success or failure.
Appends the string data along with a line terminator to the stream and advances the current stream position by the number of characters in data plus the line terminator.Returns a
%Status value indicating success or failure.
|
Selects LineNo1 As%String , Line1 As%String , LineNo2 As%String , Line2 As%String
This query provides a list of all lines that differ between two given routines.
Nsp1 and RouName1 specify the first routine.
Nsp2 and RouName2 specify the second routine.
Nsp1 and RouName2 can be either an explicit or an implied namespace.
Selects Line As%String , Match As%Boolean
The query returns the routine that contains FindWhat, one line per row, with two columns, Line and Match. Line is the line text. Match is 1 if Line contains FindWhat. The entire routine is returned.
Selects Name As%String (MAXLEN=512) AsFileName/Ext , Size As%Integer , Date As%TimeStamp , Lang As%String
This query provides a list of all routines that match the pattern specified by spec.spec may contain both * and ? as wildcards. It may also consist of more than one, comma-delimited selections. For example:
"*.MAC"
"A*.MAC"
"A?.MAC"
"A*.MAC,B*.MAC"
dir specifies the direction to search in, 1 is forwards and -1 is backwards.
type is 1 to include OBJ files in the search and the default, 0 will just include INT, MAC, INC, BAS.
nsp is the namespace to list from. If omitted, the query returns the routines from the current namespace. nsp can be either an explicit or an implied namespace.
Selects Name As%String (MAXLEN=256) AsFileName/Ext , Size As%Integer , Date As%TimeStamp
This query provides a list of all routines that match the Spec ordered by the OrderBy. The Dir specifies the direction to search in, 1 is in assending order and -1 is in decending order.Spec may contain both * and ? as wildcards. It may also consist of more than one, comma-delimited selections. For example:
"*.MAC"
"A*.MAC"
"A?.MAC"
"A*.MAC,B*.MAC"
The Type is 1 to include OBJ files in the search and the default, 0 will just include INT, MAC, INC, BAS.
OrderBy is one of:
If you wish to return the results in name order then use the RoutineList query as this is faster as it does not need to build a full list first in order to sort it correctly.
- Date - Date/Time the file was saved (the default)
- Size - Size of the file
- Type - Type of the file ie. INT, MAC, INC, BAS
nsp is the namespace to list from. If omitted, the query returns the routines from the current namespace. nsp can be either an explicit or an implied namespace.