Programmer Guide/Macro Library/CObjEx: Difference between revisions
From STX Wiki
Jump to navigationJump to search
Line 20: | Line 20: | ||
If a derived class implementa a '''construct''' or '''destruct''' member, the base class member must be called. | If a derived class implementa a '''construct''' or '''destruct''' member, the base class member must be called. | ||
; | ;public_construct: | ||
:The default constructor calls the CObj constructor and writes a construct-message to the console window. The function takes no arguments and returns always 0 (success). It must be called by derived classes. | |||
; | ;public_detsruct: | ||
:The default constructor stops and deletes the internal timer (&logTimerItem), calls the CObj destructor and writes a destruct-message to the console window. It must be called by derived classes. | |||
==Member Functions== | ==Member Functions== |
Revision as of 12:56, 7 March 2018
The class CObjEx
is an enhanced base class designed for objects which are used in STx scripts. Objects based on this class are deleted automatically before the script application is finished. By convention a class based on CObjEx
implements the following simple instantiation method:
cobjexinst := cobjExClassName constructionArguments
This instantation method can simply be implemented:
[class myclassex cobjex] exit 1 set '$(cobj 'new $#mac $#argv')' // start with member functions here ...
Contents
Rules for derived classes
If a derived class implementa a construct or destruct member, the base class member must be called.
- public_construct
- The default constructor calls the CObj constructor and writes a construct-message to the console window. The function takes no arguments and returns always 0 (success). It must be called by derived classes.
- public_detsruct
- The default constructor stops and deletes the internal timer (&logTimerItem), calls the CObj destructor and writes a destruct-message to the console window. It must be called by derived classes.
Member Functions
Cleanup (static)
cobjex cleanup
- Result
- none:
- Description
- Delete all instances of classes derived from
CObjEx
. This function is called automatically by the script controller (BScript
) before the script application exits.
Log
- Usage
cobjex_inst log text
:- text
- The text to write to the script console.
- Result
- none
- Description
- Write the message
cobjex_inst: text
to the script console.
ELog
- Usage
cobjex_inst elog lev ; res ; text
- lev
- the number of macro levels to close (1 = return to caller, 2 = exit caller, ...; default=2)
- res
- the result value to be returned; no default (empty)
- text
- The text to write to the script console.
- Result
- none
- Description
- Write the message
cobjex_inst: Error! - text
to the script console and exits the specified number of macro levels (exit lev set 'res').
LogExit
public
cobjex logError result; text
-
- result
- The result to assign after returning.
- text
- The text to write to the console window.
- Result
- The value of argument result
- Description
- Writes the message
class-instance: text
to the script console and exits from 2 macros (= return from caller) with the return value result.
LogExt
public
inst LogExt mode ; text
-
- mode
- If
0
, the text overwrites the last log window line. If 1
, the text is appended to the last log window line.
- text
- The text to write to the log window.
- Result
- none
- Description
- Write text to the
CON
log window with the option of overwriting the last line. This is useful for progress reports.
LogTimer
public
inst LogTimer cmd
-
- cmd
- One of the following:
ON
or BEGIN
: Start the timer and/or display the elapsed time the console window.
OFF
or END
: Stop the timer and display the elapsed time in the console window.
- Return
- The elapsed time in seconds.
- Description
- Start (continue) or stop the internal timer of the object and write the elapsed time to console window (using Log).
ELog
cobjex ELog level ; result ; text
-
- level
- The number of macro levels to return (
2
means: return from calling-macro).
- result
- The result to set on returning.
- text
- The text to write to the console window.
- Result
- The value of the argument result. Note: This value is returned to macro addressed by argument level.
- Description
- Writes the message
class-instance: ERROR - text
to the script console and exits from level macros with the return value result.