Page 1 of 1

Delete not updating ?

Posted: Wed Oct 31, 2007 5:16 pm
by TimStone
Here is a section of code that uses FWH 7.10, xHarbour, tSBrowse, and tData ( data object extension ). If I click on the delete button, the browse removes the record, moves to the next record, but the edit control is not updating. I have a feeling I'm missing something ... just not getting through to my brain right now. This code is cut from the full function which has some more edit and label controls.

Tim

FUNCTION list01

// Declare LOCAL variables
LOCAL oDbl, oEdit, lFirst := .F.

// Open the labor rate reference database and index
oDbl := tdata():new(, "erflab" )
oDbl:use()
oDbl:setorder( "erflab" )
oDbl:gotop()

DEFINE DIALOG oDlg RESOURCE "LISTS" OF oWnd TITLE "Labor Rates" FONT oWnd:oFont

// Build the button controls
REDEFINE BUTTON ID 107 of oDlg ACTION( IIF( MsgYesNo( "Do you wish to delete this item ?"), ( oDBl:delete( ),;
oDlg:update()),)) MESSAGE "Delete the current item"

.....

// Build the edit controls
REDEFINE GET oEdit VAR oDbl:charge ID 102 OF oDlg PICTURE "$99999.99" MESSAGE "The charge for this service" UPDATE
REDEFINE GET oDbl:servic ID 103 OF oDlg MESSAGE "A description of the service type" UPDATE

.....

// Create the BROWSE control
REDEFINE BROWSE oLbx1 ID 101 OF oDlg ON CHANGE oDlg:update() UPDATE
oLbx1:setoDBF( oDbl )
add column to oLbx1 header "Charge" data oDbl:charge ALIGN 2,1 size 120
add column to oLbx1 size 25
add column to oLbx1 Header "Service" data oDbl:servic ALIGN 0,1 size 400

.....

// Activate the dialog screen
ACTIVATE DIALOG oDlg

// Close the file
oDbl:close()

RETURN NIL
:roll:

Posted: Wed Oct 31, 2007 6:47 pm
by Armando
Timm:

I don't know TDATA, but.....

Perhaps you need read the new record to fill the bufer.

oDbl:Read()

just a tip

Regards

Buffer

Posted: Wed Oct 31, 2007 7:19 pm
by TimStone
tData has a load() method ... it makes no difference ...

Posted: Wed Oct 31, 2007 8:43 pm
by Gale FORd
I have a varying degrees of success with this subject.
I think one of the issues is that when you delete the record it is still visible and the msgyesno() function displays a dialog and the when it goes away the browse gets refreshed.

I ended up using a method/function that does the following.

Code: Select all

METHOD DataDelete
   local nRecNo, nNewRecNo, lAnswer
   // store current record before window has a chance to move record pointer
   nRecno := ::oDbf:Recno()
   // to stop refresh
   ::oWnd:disable()
   lAnswer := MsgYesNo ( "Delete record: Are you sure ?", "DELETE" )
   if lAnswer
      // Get next good record if possible
      ::oDbf:goto( nRecNo )
      ::oDbf:skip()
      if ::oDbf:eof()
         ::oDbf:goto( nRecNo )
         ::oDbf:skip( -1 )
      endif
      nNewRecNo := ::oDbf:recno()
      // Now go back and delete record
      ::oDbf:goto( nRecNo )
      ::oDbf:delete()
      ::oDbf:unlock()
      // go to new record
      ::oDbf:goto( nNewRecNo )
   endif
   // enable window
   ::oWnd:enable()
   sysrefresh()
   if lAnswer
      // There is a question whether to use upstable() with database object
      // or use refresh(). I am using refresh() with database object
      //::oBrw:Upstable()
      ::oBrw:Refresh()
      ::oBrw:setfocus()
   endif
return( nil )

Posted: Thu Nov 01, 2007 7:16 am
by James Bott
Tim,

Try adding oDbl:skip() right after oDbl:delete(). This will force the record pointer to the next record and reload the buffer.

James

Skip

Posted: Thu Nov 01, 2007 8:14 pm
by TimStone
I just did that ( prior to your post, but after thinking about Gale's post) and it does indeed force the two records ( browse and data object ) to match up. I'm thinking perhaps this is a problem in TSBrowse as it currently stands.

The oDbf:skip() does work and I can add it throughout the code.

Thanks :D