>using FWH 17.04 with TDatabase 17.04, new Close method, closing a database object, then calling it after, several times, no error.
James Bott wrote:Are you saying that you edited ver 17.04 TDatabase.prg and replaced the Close() method with the one from TDatabase 17.07?
James Bott wrote:Also, remember that no error doesn't mean that something hasn't gone wrong.
Note that if you are using TData then it overrides the Close() method of TDatabase.
James
oStates := TDatabase():New(nil, cStatesFile)
oStates:use()
? oStates:Used(), oStates:FieldGet( 1 ) // --> .T., "WA"
// do some work and close the object
oStates:Close() // dbf is closed but the object is still there
//oStates:=nil // Adding this solves the problem.
//oStates:GoTop() // errors out, any version
msgInfo(oStates:nArea,"oStates:nArea") // 1
msgINfo(oStates:used(),"oStates:used()") // .f.
oCust := TDataBase():Open( nil, cCustFile, "DBFCDX" )
? oCust:Used(), oCust:FieldGet( 1 ) // --> .T., "Homer" // this is OK
msgInfo(oCust:nArea,"oCust:nArea") // Returns 1
oStates:GoTop() // oStates is now using the workarea of oCust. No error.
// This is wrong
? oStates:Used(), oStates:FieldGet( 1 ) // --> .T., "Homer" // This is from the oCust database
oStates:Close() // Problem: This closes oCust
? oCust:Used() // --> .F., though we did not call oCust:Close()
msgInfo(oStates:used(),"oStates:used()") // returns false since oCust is closed
/*
Purpose : Very simple test showing how not destroying a database object
can cause bad things to happen.
Program :
Author : James Bott, jbott@compuserve.com
Date : 09/06/2017 11:04:49 AM
Language : Fivewin/xHarbour
Updated :
Notes :
*/
#include "fivewin.ch"
REQUEST DBFCDX
function Main()
local oStates, oCust
local cStatesFile:="c:\fwh\samples\states.dbf"
local cCustFile:="c:\fwh\samples\customer.dbf"
rddsetdefault( "DBFCDX" )
memory(-1)
oStates := TDatabase():New(nil, cStatesFile)
oStates:use()
MsgInfo( oStates:FieldGet(1),"oStates:FieldGet(1)") // "WA"
oStates:Close() // dbf is closed but the object is still there
//oStates:=nil // Adding this destroys the object
//oStates:GoTop() // errors out, any version
oCust := TDataBase():New( nil, cCustFile, "DBFCDX" )
oCust:use()
msgInfo(oCust:FieldGet( 1 ),"oCustFieldGet(1)" ) // "Homer" // this is OK
oStates:GoTop() // oStates is now using the workarea of oCust. No error.
// This is wrong
msgInfo(oStates:FieldGet(1),"oStates:FieldGet(1)") // "Homer" Wrong
oStates:Close() // Problem: This closes oCust
oCust:Close()
return nil
// EOF
METHOD Close() INLINE ( ::nArea )->( DbCloseArea() ), If( ::oCn == nil,,::oCn:Close() ) // FWH 13.03
METHOD Close() INLINE ( ::nArea )->( DbCloseArea() )
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: No registered users and 34 guests