+ contrib/hbct/tests/dates4.prg
- tests/dates4.prg
* contrib/hbnf/byt2bit.prg
* contrib/hbnf/dectobin.prg
* contrib/hbnf/popadder.prg
* tests/ac_test2.prg
* tests/ainstest.prg
* tests/and_or.prg
* tests/array16.prg
* tests/arrays.prg
* tests/begin.prg
* tests/byref.prg
* tests/calling.prg
* tests/clasinh.prg
* tests/clasinit.prg
* tests/classes.prg
* tests/clsnv.prg
* tests/codebloc.prg
* tests/dates.prg
* tests/debugtst.prg
* tests/destruct.prg
* tests/dirtest.prg
* tests/dynobj.prg
* tests/exittest.prg
* tests/fib.prg
* tests/files.prg
* tests/fornext.prg
* tests/fsplit.prg
* tests/gtchars.prg
* tests/ifelse.prg
* tests/inherit.prg
* tests/inifiles.prg
* tests/initexit.prg
* tests/inkeytst.prg
* tests/inline.prg
* tests/iotest.prg
* tests/iotest2.prg
* tests/longdev.prg
* tests/longstr2.prg
* tests/memvar.prg
* tests/multiarg.prg
* tests/newrdd.prg
* tests/nums.prg
* tests/objasign.prg
* tests/objects.prg
* tests/overload.prg
* tests/passref.prg
* tests/procname.prg
* tests/readhrb.prg
* tests/returns.prg
* tests/rto_get.prg
* tests/rto_tb.prg
* tests/sbartest.prg
* tests/setkeys.prg
* tests/speed.prg
* tests/statfun.prg
* tests/statics.prg
* tests/stripem.prg
* tests/switch.prg
* tests/tb1.prg
* tests/test_all.prg
* tests/testbrw.prg
* tests/testcls.prg
* tests/testerro.prg
* tests/testfor.prg
* tests/testmem.prg
* tests/testntx.prg
* tests/testop.prg
* tests/testpp.prg
* tests/testrdd2.prg
* tests/teststr.prg
* tests/testvars.prg
* tests/testwarn.prg
* tests/tstasort.prg
* tests/tstdbi.prg
* tests/tstmacro.prg
* tests/varparam.prg
* tests/vidtest.prg
* various cleanups, fixes and formatting
now most tests are warning and error free
66 lines
1.7 KiB
Plaintext
66 lines
1.7 KiB
Plaintext
/*
|
|
* $Id$
|
|
*/
|
|
|
|
// Testing Harbour classes and objects management
|
|
// be aware Harbour provides a much simpler way using Class HBClass
|
|
|
|
#include "hboo.ch"
|
|
|
|
PROCEDURE 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
|
|
|
|
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
|