Diego,
I have added more comments and messages to the sample code Nages provided. Perhaps this will make things more clear.
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
Note that just because you don't get an error message doesn't mean that something isn't wrong. For instance you may be getting data from a different database object. This kind of thing is very hard to find.
Closing the object doesn't destroy it and we need to destroy it to prevent these kinds of issues.
James