FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour today problem with savetodbf
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
today problem with savetodbf
Posted: Wed Aug 18, 2021 10:24 AM
Code (fw): Select all Collapse
Application
===========
   Path and name: C:\Work\errori\Ricerca_invoice_salvtaggio_ok\test.Exe (32 bits)
   Size: 4,657,664 bytes
   Compiler version: Harbour 3.2.0dev (r1904111533)
   FiveWin  version: FWH 21.06
   C compiler version: Borland/Embarcadero C++ 7.0 (32-bit)
   Windows version: 6.1, Build 7601 Service Pack 1

   Time from start: 0 hours 0 mins 8 secs 
   Error occurred at: 18-08-2021, 12:04:36
   Error description: Error BASE/1132  Limiti superati: accesso all'array
   Args:
     [   1] = A   {"","01","servizio",1,9,9,,,,0,0,"RR210818120430",.T.,.T.,"","",1,1} length: 18
     [   2] = N   19

Stack Calls
===========
   Called from: .\source\function\DBFFUNC2.PRG => FW_FIELDSPUT( 911 )
   Called from: .\source\function\DBFFUNC2.PRG => (b)FW_SAVEARRAYTODBF( 859 )
   Called from:  => AEVAL( 0 )
   Called from: .\source\function\DBFFUNC2.PRG => FW_SAVEARRAYTODBF( 859 )
   Called from: .\source\classes\DATABASE.PRG => TRIGHERESERVA:HB_EXECFROMARRAY( 0 )
   Called from: .\source\classes\DATABASE.PRG => TRIGHERESERVA:SAVEARRAYTODBF( 1624 )
   Called from: test.prg => EDITINVOICE( 327 )
   Called from: test.prg => (b)ORDERS( 84 )
   Called from: .\source\classes\BUTTON.PRG => TBUTTONBMP:CLICK( 179 )
   Called from: .\source\classes\CONTROL.PRG => TBUTTON:HANDLEEVENT( 1781 )
   Called from: .\source\classes\BUTTONB.PRG => TBUTTONBMP:HANDLEEVENT( 261 )
   Called from: .\source\classes\WINDOW.PRG => _FWH( 3560 )
   Called from:  => SENDMESSAGE( 0 )
   Called from: .\source\classes\DIALOG.PRG => TDIALOG:COMMAND( 433 )
   Called from:  => TWINDOW:HANDLEEVENT( 0 )
   Called from: .\source\classes\DIALOG.PRG => TDIALOG:HANDLEEVENT( 1140 )
   Called from:  => DIALOGBOXINDIRECT( 0 )
   Called from: .\source\classes\DIALOG.PRG => TDIALOG:ACTIVATE( 304 )
   Called from: test.prg => ORDERS( 110 )
   Called from: test.prg => MAIN( 35 )





I make the same I saw on yunus.prg
only I use 18 FIELDS

static cItemFlds := "ICO,TIPO,DESC,QTA,PREUNI,TOTQTA,DATAINI,DATAFIN,GIORNI,SCONTO,TOTALE,INVOICE,PRINTA4,PRINTPOS,STRUCTURE,BREVEDESC,PREZZOBASE,SERIAL,RECNO()"


to save I make

Code (fw): Select all Collapse
 IF oDlg:nresult == IDOK
         
          if ! Empty( oBrowse:aDeleted )
            AEval( oBrowse:aDeleted, { |a| a[ 19 ] := -a[ 19 ] } )
             oRigheInvoice:SaveArrayToDBF( cItemFlds,oBrowse:aDeleted )  save the erased lines
          endif

        
          ADel( oBrowse:aArrayData, 1, .t. )   //erase first line


         AEval( aData, { |a| a[ 12 ] := oRecPrenota:Invoice } ) // save the invoice number
         AEval( aData, { |a,i| a[ 18 ] := i } )       //serials
         xbrowser  aData
   
          oRigheInvoice:SaveArrayToDBF( cItemFlds,aData )


         //save the other filed od reservation
          oRecPrenota:Save()


     endif


where is the error ?
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: today problem with savetodbf
Posted: Wed Aug 18, 2021 12:24 PM

Silvio,

The array has only 18 elements:

        AEval( oBrowse:aDeleted, { |a| a[ 19 ] := -a[ 19 ] } )
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: today problem with savetodbf
Posted: Wed Aug 18, 2021 06:42 PM

oooppss you're right

Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: today problem with savetodbf
Posted: Wed Aug 18, 2021 08:00 PM
Antonio Linares wrote:Silvio,

The array has only 18 elements:

AEval( oBrowse:aDeleted, { |a| a[ 19 ] := -a[ 19 ] } )



Antonio I correct but there is the error on line 329

oRigheInvoice:SaveArrayToDBF( cItemFlds,aData )

Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: today problem with savetodbf
Posted: Thu Aug 19, 2021 09:06 AM

Dear Silvio,

what error is it ?

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: today problem with savetodbf
Posted: Thu Aug 19, 2021 12:41 PM
Antonio Linares wrote:Dear Silvio,

what error is it ?

the same on savearrattodbf see your mail
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: today problem with savetodbf
Posted: Thu Aug 19, 2021 02:26 PM

Silvio,

Why don't you link in the source code SaveArrayToDBF or the class and insert some msginfos?

Best regards,
Otto

Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: today problem with savetodbf
Posted: Thu Aug 19, 2021 03:00 PM
Otto wrote:Silvio,

Why don't you link in the source code SaveArrayToDBF or the class and insert some msginfos?

Best regards,
Otto

not know where is it
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: today problem with savetodbf
Posted: Thu Aug 19, 2021 03:27 PM

Silvio,
oRigheInvoice is your class?

It seems to me that you use the Fivewin function ArrayToDBF there.

c:\fwh\source\function\dbffunc2.prg

Best regards,
Otto

Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: today problem with savetodbf
Posted: Thu Aug 19, 2021 03:57 PM
Otto wrote:Silvio,
oRigheInvoice is your class?

It seems to me that you use the Fivewin function ArrayToDBF there.

c:\fwh\source\function\dbffunc2.prg

Best regards,
Otto

I re-created that I saw on yunus.prg only I have 18 Fields and use tdatabase

no oRigheInvoice is the name of dbf Rig_Res.dbf

Code (fw): Select all Collapse
 oRigheInvoice:=TRigheReserva():New()
        oRigheInvoice:setorder("res_rr")
        oRigheInvoice:gotop()




the error is on oRigheInvoice:SaveArrayToDBF( cItemFlds,aData )
I have cItemFlds 18 fields + 1 ( recno())

Code (fw): Select all Collapse
static cItemFlds := "ICO,TIPO,DESC,QTA,PREUNI,TOTQTA,DATAINI,DATAFIN,GIORNI,SCONTO,TOTALE,INVOICE,PRINTA4,PRINTPOS,STRUCTURE,BREVEDESC,PREZZOBASE,SERIAL,RECNO()"


and aData 18 fields


the error let me say

Code (fw): Select all Collapse
Time from start: 0 hours 0 mins 42 secs 
   Error occurred at: 18-08-2021, 22:36:03
   Error description: Error BASE/1132  Limiti superati: accesso all'array
   Args:
     [   1] = A   {".\bitmaps\servizio.png","01","servizio",1,9,9,,,,0,0,"RR210818223522",.T.,.T.,"","",1,1} length: 18
     [   2] = N   19

Stack Calls
===========


on error .log there is this

Procedure Type Value
==========================
FW_FIELDSPUT
Param 1: O Class: ERROR
(b)FW_SAVEARRAYTODBF
Param 1: A Len: 19
Param 2: A Len: 18


so it tells me there are 19 fields in parameter 1 and 18 in parameter 2
in parameter 1 that is cItemFlds there are 18 fields but I also had to add RECNO BECAUSE THE savearraytodbf tells me that a field must be Recno

so there is 19

instead adata has 18

and make error

see the test sample I sent you
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: today problem with savetodbf
Posted: Thu Aug 19, 2021 04:09 PM

I think oRigheInvoice has inherited from TDatabase in your source code.
This method does not yet exist in Fivewin.
Can you post more source code?
Show the source code where you create the object.

Best regards,
Otto

Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: today problem with savetodbf
Posted: Thu Aug 19, 2021 04:15 PM
Called from: .\source\function\DBFFUNC2.PRG => FW_FIELDSPUT( 911 )
Called from: .\source\function\DBFFUNC2.PRG => (b)FW_SAVEARRAYTODBF( 859 )
Called from: => AEVAL( 0 )
Called from: .\source\function\DBFFUNC2.PRG => FW_SAVEARRAYTODBF( 859 )


Link c:\fwh\source\function\dbffunc2.prg


There you have these functions:
Then put in some fwlogs and you will get the error.
Best regards,
Otto

Code (fw): Select all Collapse
function FW_SaveArrayToDBF( acFieldList, aData )

   local nSaveRec    := RECNO()

   if If( ValType( acFieldList ) == 'C', "RECNO()" $ Upper( acFieldList ), ;
      If( ValType( acFieldList ) == 'A', AScan( acFieldList, { |c| Upper( c ) == "RECNO()" } ) > 0 , ;
          .f. ) )

      AEval( aData, { |a| FW_FieldsPut( acFieldList, a ) } )
      DBGOTO( nSaveRec )
   else
      ? "One of the field name should be RECNO()"
   endif

return nil

//----------------------------------------------------------------------------//

function FW_FieldsPut( aFields, aValues, nLockWaitSecs, lAppend, bTrigger )

   local nRecNo      := 0
   local n, nLen, fld, u, v
   local nSecs       := 0
   local lReady      := .f.
   local lLocked     := .f.
   local lDelete     := .f.

   if DBINFO( DBI_ISREADONLY )
      return 0
   endif

   if ValType( aFields ) == 'A'
      if aValues == nil .and. ValType( aFields[ 1 ] ) == 'A'
         aFields     := ArrTranspose( aFields )
         aValues     := aFields[ 2 ]
         aFields     := aFields[ 1 ]
      endif
   else
      if aFields == nil
         aFields     := Array( FCOUNT() )
         for n := 1 to Len( aFields )
            aFields[ n ]   := n
         next n
      elseif ValType( aFields ) == 'C'
         aFields     := FW_ListAsArray( aFields )
      else
         aFields     := { aFields }
      endif
   endif
   if ValType( aValues ) != 'A'
      aValues     := { aValues }
   endif

   if ValType( lAppend ) == 'N'
      DBGOTO( Abs( lAppend ) )
      lDelete  := ( lAppend < 0 )
      lAppend  := nil
   elseif lAppend == nil
      n  := AScan( aFields, { |c| ValType( c ) == 'C' .and. Upper( c ) == "RECNO()" } )
      if ( n > 0 )
         DBGOTO( ABS( aValues [ n ] ) )
         lDelete  := ( aValues[ n ] < 0 )
      endif
   endif

   DEFAULT lAppend   := EOF()
   if lAppend .and. lDelete
      return 0
   endif

   if ( ! DBINFO( DBI_SHARED ) ) .or. DBINFO( DBI_ISFLOCK ) // exclusive or flocked
      if lAppend
         DBFAPPEND()
      endif
      lReady      := .t.
   endif
   if ! lReady .and. ! lAppend
      lReady      := DBRECORDINFO( DBRI_LOCKED )
   endif

   if ! lReady
      nSecs       := 0
      nLockWaitSecs  := If( nLockWaitSecs == nil, -1, If( nLockWaitSecs == 0, 120, nLockWaitSecs ) )
      do while ( ! ( lLocked := If( lAppend, ( DBAPPEND(), !NetErr() ), DBRLOCK() ) ) )  ;
               .and. nLockWaitSecs > 0 ;
               .and. nSecs < nLockWaitSecs
         SysWait( 0.5 )
         nSecs    += 0.5
      enddo
      lReady      := lLocked
   endif

   if lReady

      nRecNo      := RECNO()
      if lDelete
         DBDELETE()
      else
         if lAppend
            DBSKIP( 0 )
         endif
         nLen  := Min( Len( aFields ), Len( aValues ) )
         for n := 1 to nLen

            fld := aFields[ n ]
            if ValType( fld ) == 'C'
               fld   := If( ISDIGIT( fld ), Val( fld ), FIELDPOS( fld ) )
            endif
            if ! Empty( fld ) .and. !( FieldType( fld ) $ "+=@" )
               if ValType( u := FieldGet( fld ) ) == 'C'
                  u  := Trim( u )
               endif
               if ( v := XEval( aValues[ n ], lAppend ) ) != nil
                  if ! ( u == If( ValType( v ) == 'C', Trim( v ), v ) )
                     FieldPut( fld, v  )
                  endif
               endif
            endif
         next n

         if DELETED()
            RECALL
         endif

         if ValType( bTrigger ) == 'B'
            Eval( bTrigger )
         endif
      endif

   endif

   If lLocked
      DBRUNLOCK()
   endif

return nRecNo

//----------------------------------------------------------------------------//
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: today problem with savetodbf
Posted: Thu Aug 19, 2021 04:19 PM
Otto wrote:I think oRigheInvoice has inherited from TDatabase in your source code.
This method does not yet exist in Fivewin.
Can you post more source code?
Show the source code where you create the object.

Best regards,
Otto



??? otto

//OPEN THE DBF BODY
oRigheInvoice:=TRigheReserva():New()
oRigheInvoice:setorder("res_rr")
oRigheInvoice:gotop()

Code (fw): Select all Collapse
CLASS TXData from TDataBase

DATA cDbfPath init cFilePath(GetModuleFileName( GetInstance() ))

ENDCLASS

CLASS TReserva from TXData
   METHOD New()
ENDCLASS

METHOD New( lShared ) CLASS TReserva
   Default lShared := .t.
   ::super:Open(,::cDbfPath + "Reserva" ,"DBFCDX", lShared)
   if ::use()
      ::setOrder(1)
      ::gotop()
   endif
   RETURN Self
 CLASS TRigheReserva from TXData
   METHOD New()
ENDCLASS

METHOD New( lShared ) CLASS TRigheReserva
   Default lShared := .t.
   ::super:Open(,::cDbfPath + "Rig_Res" ,"DBFCDX", lShared)
   if ::use()
      ::setOrder(1)
      ::gotop()
   endif
   RETURN Self
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: today problem with savetodbf
Posted: Thu Aug 19, 2021 04:26 PM
Otto wrote:Called from: .\source\function\DBFFUNC2.PRG => FW_FIELDSPUT( 911 )
Called from: .\source\function\DBFFUNC2.PRG => (b)FW_SAVEARRAYTODBF( 859 )
Called from: => AEVAL( 0 )
Called from: .\source\function\DBFFUNC2.PRG => FW_SAVEARRAYTODBF( 859 )


Link c:\fwh\source\function\dbffunc2.prg


There you have these functions:
Then put in some fwlogs and you will get the error.
Best regards,
Otto

Code (fw): Select all Collapse
function FW_SaveArrayToDBF( acFieldList, aData )

   local nSaveRec    := RECNO()

   if If( ValType( acFieldList ) == 'C', "RECNO()" $ Upper( acFieldList ), ;
      If( ValType( acFieldList ) == 'A', AScan( acFieldList, { |c| Upper( c ) == "RECNO()" } ) > 0 , ;
          .f. ) )

      AEval( aData, { |a| FW_FieldsPut( acFieldList, a ) } )
      DBGOTO( nSaveRec )
   else
      ? "One of the field name should be RECNO()"
   endif

return nil

//----------------------------------------------------------------------------//

function FW_FieldsPut( aFields, aValues, nLockWaitSecs, lAppend, bTrigger )

   local nRecNo      := 0
   local n, nLen, fld, u, v
   local nSecs       := 0
   local lReady      := .f.
   local lLocked     := .f.
   local lDelete     := .f.

   if DBINFO( DBI_ISREADONLY )
      return 0
   endif

   if ValType( aFields ) == 'A'
      if aValues == nil .and. ValType( aFields[ 1 ] ) == 'A'
         aFields     := ArrTranspose( aFields )
         aValues     := aFields[ 2 ]
         aFields     := aFields[ 1 ]
      endif
   else
      if aFields == nil
         aFields     := Array( FCOUNT() )
         for n := 1 to Len( aFields )
            aFields[ n ]   := n
         next n
      elseif ValType( aFields ) == 'C'
         aFields     := FW_ListAsArray( aFields )
      else
         aFields     := { aFields }
      endif
   endif
   if ValType( aValues ) != 'A'
      aValues     := { aValues }
   endif

   if ValType( lAppend ) == 'N'
      DBGOTO( Abs( lAppend ) )
      lDelete  := ( lAppend < 0 )
      lAppend  := nil
   elseif lAppend == nil
      n  := AScan( aFields, { |c| ValType( c ) == 'C' .and. Upper( c ) == "RECNO()" } )
      if ( n > 0 )
         DBGOTO( ABS( aValues [ n ] ) )
         lDelete  := ( aValues[ n ] < 0 )
      endif
   endif

   DEFAULT lAppend   := EOF()
   if lAppend .and. lDelete
      return 0
   endif

   if ( ! DBINFO( DBI_SHARED ) ) .or. DBINFO( DBI_ISFLOCK ) // exclusive or flocked
      if lAppend
         DBFAPPEND()
      endif
      lReady      := .t.
   endif
   if ! lReady .and. ! lAppend
      lReady      := DBRECORDINFO( DBRI_LOCKED )
   endif

   if ! lReady
      nSecs       := 0
      nLockWaitSecs  := If( nLockWaitSecs == nil, -1, If( nLockWaitSecs == 0, 120, nLockWaitSecs ) )
      do while ( ! ( lLocked := If( lAppend, ( DBAPPEND(), !NetErr() ), DBRLOCK() ) ) )  ;
               .and. nLockWaitSecs > 0 ;
               .and. nSecs < nLockWaitSecs
         SysWait( 0.5 )
         nSecs    += 0.5
      enddo
      lReady      := lLocked
   endif

   if lReady

      nRecNo      := RECNO()
      if lDelete
         DBDELETE()
      else
         if lAppend
            DBSKIP( 0 )
         endif
         nLen  := Min( Len( aFields ), Len( aValues ) )
         for n := 1 to nLen

            fld := aFields[ n ]
            if ValType( fld ) == 'C'
               fld   := If( ISDIGIT( fld ), Val( fld ), FIELDPOS( fld ) )
            endif
            if ! Empty( fld ) .and. !( FieldType( fld ) $ "+=@" )
               if ValType( u := FieldGet( fld ) ) == 'C'
                  u  := Trim( u )
               endif
               if ( v := XEval( aValues[ n ], lAppend ) ) != nil
                  if ! ( u == If( ValType( v ) == 'C', Trim( v ), v ) )
                     FieldPut( fld, v  )
                  endif
               endif
            endif
         next n

         if DELETED()
            RECALL
         endif

         if ValType( bTrigger ) == 'B'
            Eval( bTrigger )
         endif
      endif

   endif

   If lLocked
      DBRUNLOCK()
   endif

return nRecNo

//----------------------------------------------------------------------------//




OTTO,

I use another function
Please see YUNUS.prg

search static function EditInvoice( oRec )


....

if ! Empty( oBrw:aDeleted )
AEval( oBrw:aDeleted, { |a| a[ 9 ] := -a[ 9 ] } )
IIT->( FW_SaveArrayToDBF( cItemFlds, oBrw:aDeleted ) )
endif

AEval( aItems, { |a| a[ 1 ] := oRec:InvNum } )
AEval( aItems, { |a,i| a[ 2 ] := i } )

IIT->( FW_SaveArrayToDBF( cItemFlds, aItems ) )

oRec:Save()

but IIT->( FW_SaveArrayToDBF( cItemFlds, aItems ) ) is not tdatabase

the method is for tdatabase SaveArrayToDBF( cItemFlds, aItems )

so odbf:SaveArrayToDBF( cItemFlds, aItems )



If I use oRigheInvoice:ArrayToDBF( aData, cItemFlds,, .t., .t. ) run but I have on dbf another error
If is a new record not save
if is a edit record modifies the lines that are in the archive even if they are not of the same order number
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: today problem with savetodbf
Posted: Thu Aug 19, 2021 04:52 PM

'Silvio,

but before you can save a record you have to navigate to the recNo

METHOD GoTo( nRecNo )
or insert a new record.
METHOD Append()

Why don't you create a function, SAVE () and pass your data?
There you open your database again and save everything.
And then closes it.

For such a complicated task, this is more transparent.
And more secure. Commit, skip problems. More save in network enviroment.

Best regards,
Otto