Page 1 of 1

TDatabase: Using own :append() adds blank records

Posted: Fri Jun 19, 2020 6:06 am
by hua
Using Harbour+FWH1912, the following sample will at 1st run generates RTE and subsequent runs will see empty records added. Why?

Code: Select all

#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
 

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

Posted: Fri Jun 19, 2020 5:52 pm
by nageswaragunupudi
Please try this modified program

Code: Select all

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