TDatabase: Using own :append() adds blank records

TDatabase: Using own :append() adds blank records

Postby hua » Fri Jun 19, 2020 6:06 am

Using Harbour+FWH1912, the following sample will at 1st run generates RTE and subsequent runs will see empty records added. Why?

Code: Select all  Expand view  RUN

#include "fivewin.ch"
function main()
  local oDb
  field dref

  if !file("hua.dbf")
     dbCreate("hua.dbf", {{"dref", "c", 12, 0}})
  endif
  oDb := TData():open(, "hua.dbf",,.t.)
  select (oDb:cAlias)
  index on dref to hua temporary

  oDb:append()

  oDb:dref := time()
  oDb:save()
  xbrowse(oDb)
return nil

class TData from TDatabase
  method open(cAlias, cDbf, cDriver, lShared) inline ::super:open(cAlias, cDbf, cDriver, lShared)
  method append() inline (::cAlias)->(myAppend())
endclass

function MyAppend()
  append blank
return nil
 
FWH 11.08/FWH 19.12
BCC5.82/BCC7.3
xHarbour/Harbour
hua
 
Posts: 1072
Joined: Fri Oct 28, 2005 2:27 am

Re: TDatabase: Using own :append() adds blank records

Postby nageswaragunupudi » Fri Jun 19, 2020 5:52 pm

Please try this modified program

Code: Select all  Expand view  RUN
#include "fivewin.ch"

function main()
  local oDb
  field dref

  if !file("hua.dbf")
     dbCreate("hua.dbf", {{"DREF", "C", 12, 0}})
  endif
  oDb := TData():open(, "hua.dbf",,.t.)
//  select (oDb:cAlias) // let us not directly handle the alias/area
//  index on dref to hua temporary
  oDb:CreateIndex( nil, "DREF", "DREF", nil, nil, .T. ) // .T. for temporary index

  //
  oDb:Blank()     //oDb:append()
  oDb:dref := time()
  oDb:save()
  XBROWSER oDb

  oDb:Append( { "dref" }, { time() } )
  XBROWSER oDb

  oDb:Blank()
  oDb:dref := time()
  oDb:save()
  XBROWSER oDb

return nil

class TData from TDatabase
  method open(cAlias, cDbf, cDriver, lShared) inline ::super:open(cAlias, cDbf, cDriver, lShared)
//  method append() inline (::cAlias)->(myAppend()) // do not override append()
endclass

/*
function MyAppend()
  append blank
return nil
*/

 
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10651
Joined: Sun Nov 19, 2006 5:22 am
Location: India


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 81 guests