FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Error in Tdatabase version 1804 ?
Posts: 230
Joined: Sat Apr 19, 2008 10:28 PM
Error in Tdatabase version 1804 ?
Posted: Thu Dec 20, 2018 06:48 PM
Hi,

I am using FWH 1804. I have a problem with Tdatabase. The same program worked with my previous version 1204
I am using dbf files with cdx index

I use:

Code (fw): Select all Collapse
oDatabase:load()


then I have a dialog if the "save" button is pressed lSave is true, if Cancel button is pressed lSave is false

Code (fw): Select all Collapse
if lSave
  oDatabase:save()
endif


Well, the record is always saved, even if the save() method is not executed. I mean, if the cancel button is pressed the record is saved anyway.

Is there an error in this version? It worked before.

Thank you very much

Alvaro
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Error in Tdatabase version 1804 ?
Posted: Thu Dec 20, 2018 07:22 PM

If oDbf:lBuffer is .T. (this is the default), changes are saved only if we execute oDbf:Save() and otherwise not saved.

If oDbf:lBuffer is set to .f., then any changes made are written to the dbf.

Actually there is no need to call oDbf:load() specifically in the program. This is done automatically by TDatabase class if oDbf:lBuffer is .t. ( default ).

Can you please provide a small test program using any of the dbf in fwh\samples folder ( eg. \fwh\samples\states.dbf ) to help us to build your sample and test at our end.

Regards



G. N. Rao.

Hyderabad, India
Posts: 230
Joined: Sat Apr 19, 2008 10:28 PM
Re: Error in Tdatabase version 1804 ?
Posted: Thu Dec 20, 2018 09:35 PM
Hi,

Thank you for your answer. Please try this code. Please use \fwh\samples\states.dbf.

You can see that if you press "Cancel" the record is also saved. Thank you and regards.

Code (fw): Select all Collapse
// ------------------------------------------------------------------------------- //
function error_tdatabase()
local nSele := select()
local oDatabase
local cAlias
local oWnd
local oBar

use states new alias (cAlias:="states" )
database oDatabase

define window oWnd   title "Test"   

DEFINE BUTTONBAR oBar 3D OF oWnd size 40,60  2007
define button of obar name "back"  Prompt "Esc" action (ownd:end()) tooltip "Close Windows"
define button of obar name "edit"  Prompt "Edit" action error_tdatabase2(oDatabase) tooltip "Edit record"



activate window oWnd valid ( (cAlias)->( dbclosearea() ) , select(nSele) , .t.)


return nil


// ------------------------------------------------------------------------------- //
function error_tdatabase2(oDatabase)
local oDlg
local lSave := .f.


define dialog oDlg title "Test" size  500 , 300 pixel

@ 10 , 10 say  oDatabase:code size 40,12 pixel of oDlg
@ 30 , 10 get oDatabase:name size 200,12 pixel of oDlg
@ 120 , 150 button "Cancel" size 40,10 pixel of oDlg action oDlg:end()
@ 120 , 200 button "Save" size 40,10 pixel of oDlg action (lSave:=.t. , oDlg:end() )
activate dialog oDlg centered

if lSave
   oDatabase:save()
   msginfo("Saved")
else
   msginfo("Not saved")
endif


return nil
Posts: 230
Joined: Sat Apr 19, 2008 10:28 PM
Re: Error in Tdatabase version 1804 ?
Posted: Thu Dec 20, 2018 10:03 PM

Hi again.

I realized that the record is not actually saved, but if you press twice or three times the button “Cancel”, the value of oDatabase:name is changed, even if you say oDatabase:load() before the dialog. If you don’t understand my point I will give you an example. Regards

Alvaro

Posts: 230
Joined: Sat Apr 19, 2008 10:28 PM
Re: Error in Tdatabase version 1804 ?
Posted: Thu Dec 20, 2018 10:21 PM

I solved it.

If I say oDatabase:load(.t.) before editing everything is fine. Thank you
Alvaro

Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Error in Tdatabase version 1804 ?
Posted: Fri Dec 21, 2018 02:42 AM
Suggested:
Code (fw): Select all Collapse
if lSave
   oDatabase:save()
   msginfo("Saved")
else
   oDatabase:Skip( 0 ) // clear changes in buffer (or) oDataBase:Load( .t. )
   msginfo("Not saved")
endif
Regards



G. N. Rao.

Hyderabad, India
Posts: 230
Joined: Sat Apr 19, 2008 10:28 PM
Re: Error in Tdatabase version 1804 ?
Posted: Fri Dec 21, 2018 02:46 AM

Thanks a lot
Alvaro

Continue the discussion