xHarbour Reference Documentation > Statement Reference xHarbour Developers Network  

ACCESS

Declares an ACCESS method of a class.

Syntax

ACCESS <MethodName> [ INLINE <expression> | VIRTUAL ]

Arguments

<MethodName>
This is the symbolic name of the access method to implement. It must begin with a letter or underscore followed by digits, letters or underscores. The symbolic name can contain up to 63 characters.
INLINE <expression>
Normally, access methods are implemented outside the class declaration, using a regular METHOD (implementation). When an access method is implemented as INLINE method, <expression> is executed when the access method is invoked. <expression> must be one line of code. The code cannot contain commands but only function and method calls.
VIRTUAL
An access method can be declared as VIRTUAL method. The VIRTUAL and INLINE clauses are mutually exclusive.

Description

An ACCESS method is a special method since it is invoked when an object receives a message "as if" an instance variable is queried. Sending <MethodName> without including parentheses to an object results in the method call. ACCESS methods "simulate" an instance variable for the calling context.

An object can have "computed" instance variables whose values are the result of a method call. An ACCESS method "hides" the method call from the calling context.

Another special method type can be declared with ASSIGN which "simulates" the write access to an instance variable via a method call.

Info

See also:ASSIGN, CLASS, DATA, EXPORTED:, METHOD (declaration), METHOD...VIRTUAL
Category: Class declaration , Declaration , xHarbour extensions
Header:hbclass.ch
Source:vm\classes.c
LIB:xhb.lib
DLL:xhbdll.dll

Example

// The example implements a class that uses ACCESS methods
// for simulating instance variables.

   #include "hbclass.ch"

   PROCEDURE Main
      LOCAL obj := Someday():new()

      // real instance variable
      ? obj:date             // result: 08/31/06

      // "simulated" instance variables
      ? obj:yesterday        // result: Wednesday
      ? obj:today            // result: Thursday
      ? obj:tomorrow         // result: Friday

      ? obj:nextWeek         // result: 09/04/06
   RETURN

   CLASS Someday
      EXPORTED:
      DATA   date INIT Date()

      ACCESS today
      ACCESS tomorrow
      ACCESS yesterday
      ACCESS nextWeek
   ENDCLASS

   METHOD today
   RETURN CDoW( ::date )

   METHOD tomorrow
   RETURN CDoW( ::date + 1 )

   METHOD yesterday
   RETURN CDoW( ::date - 1 )

   METHOD nextWeek
      LOCAL nDays := -1

      // find next Monday
      DO WHILE DoW( ++nDays + ::date ) <> 2
      ENDDO
   RETURN ::date + nDays

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