xHarbour Reference Documentation > Operator Reference xHarbour Developers Network  

:

Send operator (unary): sends a message to an object.

Syntax

<object>:<message>[ ( [<params,...>] ) ]

Arguments

<object>
<object> is a variable holding an object to which the message is sent.
<message>
<message> is the name of an instance variable or method. When a method is called on the object, the message name must be followed with parentheses.
<params,...>
<params,...> is an optional comma separated list of parameters passed to a method.

Description

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.

Info

See also:CLASS, DATA, METHOD (Implementation)
Category: Special operators , Operators
Header:hbclass.ch
LIB:xhb.lib
DLL:xhbdll.dll

Example

// 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

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe