xHarbour Reference Documentation > Statement Reference |
Declares an ACCESS method of a class.
ACCESS <MethodName> [ INLINE <expression> | VIRTUAL ]
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.
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 |
// 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
http://www.xHarbour.com