Page 1 of 1

perhaps error on tdatabase - resolved

Posted: Mon Apr 05, 2021 10:37 am
by Silvio.Falconi
Using my application with tdatabase
This error came out, so it is not related to the Tplan class but to the management of archives
I start by using the samplePlan class modified in tdatabase by Nages
the only modification I made is to embed it in the window using a dialog like tfsdi (alanit) and using two tPanels one for the lmenu and one to host the Tplan class.

I did a lot of tests this week without having had any kind of problem

this morning i wanted to try again and i got this error that i can't solve

Image

Error occurred at: 05-04-2021, 12:26:18
   Error description: Error DBCMD/2001  Workarea non in use: DBGOTOP

Stack Calls
===========
   Called from:  => DBGOTOP( 0 )
   Called from: .\source\classes\DATABASE.PRG => (b)TDATABASE( 202 )
   Called from: .\source\classes\DATABASE.PRG => TDATABASE:GOTOP( 0 )
   Called from: source\booking\PBook.prg => SAMPLEPLAN:LOADROOMS( 826 )

LoadRooms method
 

Code: Select all | Expand

METHOD LoadRooms()  CLASS SamplePlan
       local n
       local cRowName, cRowText
       local oData

       ::oRooms:GoTop()
       ::oPlann:hRows := {=>}

       DO WHILE ! ::oRooms:Eof()
          If AllTrim(::oRooms:TYPE ) == AllTrim( ::cTypeRoom ) ;
             .AND. val(right( ::oRooms:ID,3))  >= ::nNumFrom  ;
             .AND. val(right( ::oRooms:ID,3)) <= ::nNumTo

             ::oPlann:AddRow( ::oRooms:ID, ::oRooms:NAME)

       Endif
          ::oRooms:Skip( 1 )
       ENDDO

    RETURN nil

Re: perhaps error on tdatabase

Posted: Mon Apr 05, 2021 12:35 pm
by nageswaragunupudi
Error description: Error DBCMD/2001 Workarea non in use: DBGOTOP

You might have closed the alias.

How do you open TDatabase object.

Re: perhaps error on tdatabase

Posted: Mon Apr 05, 2021 1:01 pm
by Silvio.Falconi
::oRooms := TDatabase():Open( nil, cDir+"ROOMS", "DBFCDX", .t. )
::oRooms:SetOrder( "rooms_id" )
::oRooms:GoTop()

::oReserva := TDatabase():Open( nil, cDir+"RESERVA", "DBFCDX", .t. )
::oReserva:SetOrder( "room_in" )
::oReserva:GoTop()


but I'm thinking on a function I use another alias of oRooms to give the total

Code: Select all | Expand


Function TotaliElementi(cTipo,cDir)
    Local nTotali:= 0
    Local oRoomNumbers
    Local nArea    := Select()

    oRoomNumbers   := TDatabase():Open( nil, cDir+"Rooms",   "DBFCDX", .t. )
    oRoomNumbers:SetOrder( 1 )
    oRoomNumbers:GoTop()

    oRoomNumbers:Exec( < ||
         SET FILTER TO AllTrim( FIELD->TYPE ) == AllTrim( cTipo )
    return nil
    > )
        oRoomNumbers:Gotop()
       nTotali:= oRoomNumbers:OrdKeyCount()
       oRoomNumbers:SetFilter( "" )
       oRoomNumbers:close()

    Select (nArea)
Return  nTotali
 

perhaps this is the problem ?
I must converte also this on a method as

Code: Select all | Expand

Method  TotaliElementi(cTipo)  CLASS SamplePlan
    Local nTotali:= 0

    ::oRooms:SetOrder( 1 )
    ::oRooms:GoTop()
    ::oRooms:Exec( < ||
         SET FILTER TO AllTrim( FIELD->TYPE ) == AllTrim( cTipo )
    return nil
    > )
        ::oRooms:GoTop()
            nTotali:= ::oRooms:OrdKeyCount()
       ::oRooms:SetFilter( "" )

Return  nTotali

Re: perhaps error on tdatabase

Posted: Mon Apr 05, 2021 3:49 pm
by nageswaragunupudi
After
oDbf := TDataBase():Open(...)
check
if oDbf:Used()
? "opened"
else
? "not opened"
endif

Re: perhaps error on tdatabase

Posted: Mon Apr 05, 2021 4:48 pm
by Silvio.Falconi
nageswaragunupudi wrote:After
oDbf := TDataBase():Open(...)
check
if oDbf:Used()
? "opened"
else
? "not opened"
endif


thanks but the error did not come out

probably because even if I used another area oRoomNumbers of the same archive (room.dbf)
when I went to close oRoomNumbers: close () I also closed :: oRooms otherwise the error is not explained
I changed the function to a method and it seems to be fine

Re: perhaps error on tdatabase - resolved

Posted: Wed May 12, 2021 5:07 pm
by James Bott
Silvio,

Whenever you manipulate an open database using either a function or a method you need to save it's state (recno(), filter, index, etc.) and then restore it at the end of the method or function.

However, what I do instead is just open a new copy of the database (even if it is a method of the database class) then do your thing, then close it. This way there is no saving and restoring the state needed.

If you don't do this, you will likely get some strange errors that may not even be repeatable, and they will be very hard to track down.

James