Page 1 of 1

Problem to save record from array (ArrayToDBF)

Posted: Thu Apr 29, 2021 8:55 am
by Silvio.Falconi
As an example I use the same technique created by Nages in yunus.prg
even if I didn't understand why it doesn't work and gives me an error

I use tdatabase

oReservation:=TDatabase():Open( , cDir+"Reserva", "DBFCDX", .T. )
oReservation:setorder(1)
oReservation:gotop()

oPartres:=TDatabase():Open( , cDir+"ResItems", "DBFCDX", .T. )
oPartres:setorder(1)
oPartres:gotop()



at the beginning I declare all the fields of my detail archive

static cItemFlds := "INVNUM,SERIAL,ITEMIMG,ITEMCODE,ITEMNAME,QUANTITY,PRICE,TOTALQ,CHECK_IN,CHECK_OUT,DAYS,DISCOUNT,TOTAL,ITEMSTRUCT,ITEMMULTI,ITEMPRNA4,ITEMPRNPOS,recno()"

at first I create the array for the xbrowse

aItems := ( oPartres:cAlias )->( FW_DbfToArray( cItemFlds, { || AllTrim( FIELD->INVNUM ) = alltrim(nInvoice) }) )


If I delete a record on xbrowse I use ADel( oBrowse:aArrayData, oBrowse:nArrayAt, .t. )

when I must save I made

//before the deleted of xbrowse

if ! Empty( oBrowse:aDeleted )
oPartRes:ArrayToDBF( oBrowse:aDeleted, cItemFlds,nil , .t., .t. )
Endif
except recalling the deleted and filtering by num invoice

SET DELETED ON
oPartRes:setorder(0)
oPartRes:Exec( < ||
SET FILTER TO AllTrim( FIELD->INVNUM ) = alltrim(nInvoice)
return nil
> )
oPartRes:gotop()
oPartRes:ArrayToDBF( aItems, cItemFlds,nil , .t., .t. )
oPartRes:SetFilter( "" )

but it doesn't save anything or it gives me an error on the number of fields