xHarbour Reference Documentation > Operator Reference |
Send operator (unary): sends a message to an object.
<object>:<message>[ ( [<params,...>] ) ]
A class defines instance variables and methods for its objects. Accessing an object's instance variable or executing one of its methods requires the object to receive a corresponding message. This is the task of the Send operator (:).
To access an instance variable, the message is sent without following parentheses. As a result, the object returns the value of the instance variable that corresponds to the message.
Methods, in contrast, are invoked by adding parentheses to the message and passing an optional list of parameters to the method. Parameters are listed inside the parentheses.
The double send operator :: has a special meaning within the context of the program code of methods. It is an abbreviation for self:, i.e. :: sends messages to the object that executes a method.
Note that only messages are understood by an object that are declared in the object's class. In addition, only those instance variables and methods are accessible that are visible in the current program context. If either an instance variable/method is not declared or currently not visible, the message is not understood by the object and a runtime error is generated.
See also: | CLASS, DATA, METHOD (Implementation) |
Category: | Special operators , Operators |
Header: | hbclass.ch |
LIB: | xhb.lib |
DLL: | xhbdll.dll |
// The example demonstrates the use of the single and // double send operator. Note that the double send operator // is only used within the program code of a method. #include "hbclass.ch" PROCEDURE Main LOCAL obj := MyClass():new( "Hello World" ) obj:display() // shows: Hello World obj:value := "Hi there" obj:display() // shows: Hi there RETURN CLASS MyClass EXPORTED: DATA value METHOD new( cString ) CONSTRUCTOR METHOD display ENDCLASS METHOD new( cString ) CLASS MyClass ::value := cString RETURN self METHOD display CLASS MyClass ? ::value RETURN self
http://www.xHarbour.com