Error in Tdatabase version 1804 ?

Error in Tdatabase version 1804 ?

Postby alvaro533 » Thu Dec 20, 2018 6: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: Select all  Expand view
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  Expand view

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
alvaro533
 
Posts: 206
Joined: Sat Apr 19, 2008 10:28 pm
Location: Madrid, España

Re: Error in Tdatabase version 1804 ?

Postby nageswaragunupudi » Thu Dec 20, 2018 7: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
User avatar
nageswaragunupudi
 
Posts: 10254
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Error in Tdatabase version 1804 ?

Postby alvaro533 » Thu Dec 20, 2018 9: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: Select all  Expand view

// ------------------------------------------------------------------------------- //
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
 
alvaro533
 
Posts: 206
Joined: Sat Apr 19, 2008 10:28 pm
Location: Madrid, España

Re: Error in Tdatabase version 1804 ?

Postby alvaro533 » 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
alvaro533
 
Posts: 206
Joined: Sat Apr 19, 2008 10:28 pm
Location: Madrid, España

Re: Error in Tdatabase version 1804 ?

Postby alvaro533 » Thu Dec 20, 2018 10:21 pm

I solved it.

If I say oDatabase:load(.t.) before editing everything is fine. Thank you
Alvaro
alvaro533
 
Posts: 206
Joined: Sat Apr 19, 2008 10:28 pm
Location: Madrid, España

Re: Error in Tdatabase version 1804 ?

Postby nageswaragunupudi » Fri Dec 21, 2018 2:42 am

Suggested:
Code: Select all  Expand view
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
User avatar
nageswaragunupudi
 
Posts: 10254
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Error in Tdatabase version 1804 ?

Postby alvaro533 » Fri Dec 21, 2018 2:46 am

Thanks a lot
Alvaro
alvaro533
 
Posts: 206
Joined: Sat Apr 19, 2008 10:28 pm
Location: Madrid, España


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: RSalazarU and 15 guests