Page 1 of 1

Error in Tdatabase version 1804 ?

Posted: Thu Dec 20, 2018 6:48 pm
by alvaro533
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: Select all

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: Select all

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

Re: Error in Tdatabase version 1804 ?

Posted: Thu Dec 20, 2018 7:22 pm
by nageswaragunupudi
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.

Re: Error in Tdatabase version 1804 ?

Posted: Thu Dec 20, 2018 9:35 pm
by alvaro533
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: Select all

// ------------------------------------------------------------------------------- //
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
 

Re: Error in Tdatabase version 1804 ?

Posted: Thu Dec 20, 2018 10:03 pm
by alvaro533
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

Re: Error in Tdatabase version 1804 ?

Posted: Thu Dec 20, 2018 10:21 pm
by alvaro533
I solved it.

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

Re: Error in Tdatabase version 1804 ?

Posted: Fri Dec 21, 2018 2:42 am
by nageswaragunupudi
Suggested:

Code: Select all

if lSave
   oDatabase:save()
   msginfo("Saved")
else
   oDatabase:Skip( 0 ) // clear changes in buffer (or) oDataBase:Load( .t. )
   msginfo("Not saved")
endif
 

Re: Error in Tdatabase version 1804 ?

Posted: Fri Dec 21, 2018 2:46 am
by alvaro533
Thanks a lot
Alvaro