Statement METHOD (Declaration) Foundation

Declares instance methods of a class (methods of the instance objects)

Syntax
METHOD <MethodName,...>
or
METHOD <MessageName> [IS <MethodName>] [IN <SuperClass>]
Parameters
<MethodName,...>
<MethodName,...> is a comma separated list with the names of the instance methods being declared. The name for a method follows the same convention as function and variable names. It must begin with a underscore or a letter and must contain alpha numeric characters. The first 255 characters are significant.
<MessageName>
<MessageName> designates the message which must be sent to an object so that it executes the method with the name <MethodName>. Including <MessageName> is generally required only when several superclasses are available in the class hierarchy which have methods with the same name.
<MethodName>
When the option IS is used, a list of method names cannot be declared. In this case only a single method name is permitted in the declaration METHOD. The method with the name <MethodName> is executed when the object receives the message <MessageName>.
<SuperClass>
When multiple superclasses have the same method <MethodName>it can be specified explicitly from which superclass a method is to be called when an object receives the message <MessageName>. Only class methods of a superclass which are visible (which are not declared with the attribute HIDDEN: within the superclass declaration) can be referenced.
Description

The declaration METHOD within the class declaration (between the CLASS...ENDCLASS statements) declares a method as an instance method of the class. Instance methods can be executed from all instances (objects) of a class, but not from the class object.

The method must be declared in the class declaration (between the CLASS...ENDCLASS statements) by the declaration METHOD <MethodName>. The code for the method must be programmed separately after the statement ENDCLASS. If the method is already implemented in a superclass or is associated with a specific superclass by the option IN, the method does not need to be programmed within this class. An object of this new class executes the source code from the superclass for the corresponding method. When the method <MethodName> is implemented both in a superclass and in this declared class, an object of the class executes this class method and not the method of the same name in a superclass.

Within the source code of a method, the object executing the method can always be referenced through the variable self. In sending a message to the object from within the code of a method (to access a member variable or execute another method) the operator :: can be used as an abbreviation for self:.

The name of the instance method is always <MethodName> where it prefaces the method's code. When the method is declared as <MessageName> IS <MethodName>, <MessageName> determines the message which must be sent to an object so that the method <MethodName> is executed.

<MessageName> can be used to define an alternative name for a method. It can also be used when the instance method is not implemented in the declared class but in one of its superclasses. When two or more superclasses exist which have the same names for methods, it is recommended that unique alternative names be declared to call the methods in each superclass. In this case the declaration is used in the form METHOD..IS..IN.

The visibility of a method is determined by the visibility attribute set with one of the statements EXPORTED:, PROTECTED: or HIDDEN: (see the section on each visibility attribute for more information).

Within a class, the name for each method must be unique. When several classes are programmed in a single file, the same method name can be declared in different classes and thus be declared several times within the same file. Methods differ in this way from functions. The name of a method can be identical to the name of a member variable, since the call to a method must always include parentheses. When no parentheses are used with a message send, it indicates that a member variable is being accessed.

Reserved names: The identifier new is reserved and cannot be used for a method name. Also the identifier init is reserved for the initialization of an instance (object).

Examples
METHOD declaration
// 
// Class declaration 
// 
CLASS Label 
  EXPORTED:                         // Globally visible 
     VAR     nRow, nCol, cLabel, cColor 

     METHOD  init, Show 
ENDCLASS 

Feedback

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.