[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
A constructor is an M entry point that is called when a new instance of a class is created.
A constructor must be the first entry point in a class routine, its tag must match the class/routine name, and it must take two arguments, THIS
and INIT
.
THIS
represents the instance of the object being accessed, and INIT
represents an initializer that can be used to assign an initial value to the object when instantiating the class.
A constructor looks like this:
%FRACTION(THIS,INIT):OBJECT ; S THIS("NUMERATOR"):PRIVATE=$P(INIT,"/",1) S THIS("DENOMINATOR"):PRIVATE=$P(INIT,"/",2) Q
Syntax
<class-name>(THIS,INIT)[:<superclass>]
In the above example, <superclass> represents the name of a class from which this class should inherit. In this case, the FRACTION
class inherits from the OBJECT
class. Note that this is not strictly necessary in this case, as all classes in FreeM automatically inherit from OBJECT
.
This document was generated on May 5, 2025 using texi2html 5.0.