The behavior is the same with both Harbour and xHarbour. So, instead of considering it as a bug, we better consider it as the expected behavior.
The value is assigned to the data at the time creation of the object, not at the time of every instantiation. Following example clarifies the behavior.
- Code: Select all Expand view
#include "fivewin.ch"
function Main()
? time(), test():ctime
? time(), test():ctime
? time(), test():new():ctime,test2():new():ctime,test3():new():ctime
return nil
class test
data ctime init time()
endclass
class test2 from test
endclass
class test3 from test
data ctime init time()
endclass
I confess that I did not know this earlier.
The lesson is that we should not use INIT to assign the result of a function, whose value may change during runtime.
We need to modify tdatabase class. These are the two changes made:
Old code:
- Code: Select all Expand view
DATA cDriver AS CHARACTER INIT RddSetDefault()
New code:
- Code: Select all Expand view
DATA cDriver // AS CHARACTER INIT RddSetDefault() // FWH16.03
Old code:
- Code: Select all Expand view
METHOD Use() CLASS TDataBase
if Empty( ::cAlias )
::cAlias := cGetNewAlias( 'TDF' )
endif
if Select( ::cAlias ) > 0
::cAlias := cGetNewAlias( Left( ::cAlias, 3 ) )
endif
dbUseArea( .t., ::cDriver, ::cFile, ::cAlias, ::lShared, ::lReadOnly )
if Alias() == ::cAlias
::SetArea( Select() )
endif
return ::Used()
New code:
- Code: Select all Expand view
METHOD Use() CLASS TDataBase
if Empty( ::cAlias )
::cAlias := cGetNewAlias( 'TDF' )
endif
if Select( ::cAlias ) > 0
::cAlias := cGetNewAlias( Left( ::cAlias, 3 ) )
endif
DEFAULT ::cDriver := RDDSETDEFAULT() // Now inserted FWH 16.03
dbUseArea( .t., ::cDriver, ::cFile, ::cAlias, ::lShared, ::lReadOnly )
if Alias() == ::cAlias
::SetArea( Select() )
endif
return ::Used()