* tests/ainstest.prg
* tests/array16.prg
* tests/arrays.prg
* tests/atest.prg
* tests/clasinit.prg
* tests/classch.prg
* tests/classes.prg
* tests/dates.prg
* tests/db_brows.prg
* tests/ddate.prg
* tests/debugtst.prg
* tests/dynobj.prg
* tests/files.prg
* tests/gfx.prg
* tests/inline.prg
* tests/keywords.prg
* tests/objects.prg
* tests/onidle.prg
* tests/readhrb.prg
* tests/rtfclass.prg
* tests/speed.prg
* tests/switch.prg
* tests/test_all.prg
* tests/testbrw.prg
* tests/testcgi.prg
* tests/testcls.prg
* tests/testget.prg
* tests/testhtml.prg
* tests/testidle.prg
* tests/testinit.prg
* tests/testntx.prg
* tests/testpers.prg
* tests/testrdd2.prg
* tests/teststr.prg
* tests/tstblock.prg
* tests/tstmacro.prg
* tests/videotst.prg
* tests/vidtest.prg
* tests/wcecon.prg
* Cleanups. SVN header, '=' operator usage.
67 lines
1.7 KiB
Plaintext
67 lines
1.7 KiB
Plaintext
//
|
|
// $Id$
|
|
//
|
|
|
|
// Testing Harbour classes and objects management
|
|
// be aware Harbour provides a much simpler way using Class HBClass (source\rtl\class.prg)
|
|
|
|
#include "hboo.ch"
|
|
|
|
function Main()
|
|
|
|
local oObject := TAny():New()
|
|
|
|
QOut( ValType( oObject ) )
|
|
QOut( Len( oObject ) ) // 3 datas !
|
|
QOut( oObject:ClassH() ) // retrieves the handle of its class
|
|
|
|
QOut( oObject:ClassName() ) // retrieves its class name
|
|
|
|
oObject:Test() // This invokes the below defined Test function
|
|
// See QSelf() and :: use
|
|
QOut( oObject:cName )
|
|
|
|
oObject:DoNothing() // a virtual method does nothing,
|
|
// but it is very usefull for Classes building logic
|
|
|
|
return nil
|
|
|
|
function TAny() /* builds a class */
|
|
|
|
static hClass
|
|
|
|
if hClass == nil
|
|
hClass := __clsNew( "TANY", 3 ) // cClassName, nDatas
|
|
__clsAddMsg( hClass, "cName", 1, HB_OO_MSG_DATA ) // retrieve data
|
|
__clsAddMsg( hClass, "_cName", 1, HB_OO_MSG_DATA ) // assign data. Note the '_'
|
|
__clsAddMsg( hClass, "New", @New(), HB_OO_MSG_METHOD )
|
|
__clsAddMsg( hClass, "Test", @Test(), HB_OO_MSG_METHOD )
|
|
__clsAddMsg( hClass, "DoNothing", 0, HB_OO_MSG_VIRTUAL )
|
|
endif
|
|
|
|
/* warning: we are not defining datas names and methods yet */
|
|
|
|
return __clsInst( hClass ) // creates an object of this class
|
|
|
|
static function New()
|
|
|
|
local Self := QSelf()
|
|
|
|
QOut( ValType( Self ) )
|
|
QOut( "Inside New()" )
|
|
|
|
::cName := "Harbour OOP"
|
|
|
|
return Self
|
|
|
|
static function Test()
|
|
|
|
local Self := QSelf() // We access Self for this method
|
|
|
|
QOut( "Test method invoked!" )
|
|
|
|
QOut( ::ClassName() ) // :: means Self: It is a Harbour built-in operator
|
|
|
|
return nil
|
|
|