to Nages : probl..FW_ArrayToDbf with tdatabase - RESOLVED!!

Re: to Nages : probl..FW_ArrayToDbf with tdatabase - RESOLVED!!

Postby nageswaragunupudi » Wed Jan 30, 2019 8:12 pm

The sample I provided above is converted to use TDatabase.
Code: Select all  Expand view
#include "fivewin.ch"

REQUEST DBFCDX

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

function Main()

   field ORDINE

   local oDlg, oBrw, oFont, oServizi
   local cSwapFields:="id,name,breve,price,image,struttura,unit,a4,pos,multiple,islock" //,ordine"

   SET DELETED ON

   BuildDBF()

   oServizi := TDatabase():Open( , "SERVIZI", "DBFCDX", .T. )
   oServizi:bTrigger := { || If( Empty( ORDINE ), ORDINE := RECNO(), nil ) }
   oServizi:SetOrder( 0 )
   oServizi:GoTop()

   DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-12
   DEFINE DIALOG oDlg SIZE 900,300 PIXEL TRUEPIXEL FONT oFont TITLE "SERVIZI.DBF"
   @ 70,20 XBROWSE oBrw SIZE -20,-20 PIXEL OF oDlg ;
      DATASOURCE oServizi AUTOCOLS ;
      LINES NOBORDER

   WITH OBJECT oBrw
      :nMarqueeStyle       := MARQSTYLE_HIGHLROW
      :AutoFit()
      :SetChecks()
      :bChange          := { || oDlg:AEvalWhen() }
      //
      :CreateFromCode()
   END

   @ 15, 20 BUTTON "ADD"  SIZE 100,40 PIXEL OF oDlg ACTION AddRec( oBrw )
   @ 15,240 BUTTON "UP"   SIZE 100,40 PIXEL OF oDlg ;
      WHEN oBrw:KeyNo > 1 ;
      ACTION SwapRec( oBrw, VK_UP, cSwapFields )
   @ 15,350 BUTTON "DOWN" SIZE 100,40 PIXEL OF oDlg ;
      WHEN oBrw:KeyNo < oBrw:nLen ;
      ACTION SwapRec( oBrw, VK_DOWN, cSwapFields )

   ACTIVATE DIALOG oDlg CENTERED
   RELEASE FONT oFont

return nil

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

static function SwapRec( oBrw, nKey, cList )

   local nRec, aRows

   WITH OBJECT oBrw:oDbf
      if nKey == VK_UP
        :Skip( -1 )
        if :Bof()
           :GoTop()
        else
           nRec     := :RecNo()
           aRows    := :DbfToArray( cList, nil, nil, 2 )
           :GoTo( nRec )
           if Len( aRows ) == 2
              AINS( aRows, 1, aRows[ 2 ] )
              :ArrayToDBF( aRows, cList, nil, .T. )
              :GoTo( nRec )
           endif
        endif
     elseif nKey == VK_DOWN
        nRec     := :RecNo()
        aRows    := :DbfToArray( cList, nil, nil, 2 )
        :GoTo( nRec )
        if Len( aRows ) == 2
           AINS( aRows, 1, aRows[ 2 ] )
           :ArrayToDBF( aRows, cList, nil, .T. )
           :GoTo( nRec )
           :Skip( 1 )
        endif
     endif
   END

   oBrw:Refresh()
   oBrw:SetFocus()

return nil

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

static function AddRec( oBrw )

   local oRec  := oBrw:oDbf:Record( .t. )

   oRec:oBrw   := oBrw
   oRec:FieldReadOnly( "ORDINE", .t. )
   oRec:Edit()

return nil

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

Function BuildDbf()

   field ID,NAME,ORDINE

   local oDbf
   local aCols       := { ;
                     { "id"    , "C",    4, 0 },;
                     { "name"  , "C",   30, 0 },;
                     { "breve"  , "C",  10, 0 },;
                     { "price" , "N",    9, 2 },;
                     { "image" , "C",   30, 0 },;
                     { "struttura","C", 30, 0 },;
                     { "unit"  , "N",    4, 0 },;
                     { "a4"    , "L",    1, 0 },;
                     { "pos"   , "L",    1, 0 },;
                     { "multiple", "L",  1, 0 },;
                     { "islock"  , "L",  1, 0 },;
                     { "ordine"  , "N",  2, 0 } }

 //sample data
   local aData       := { ;
{ "0001","Lettino","ser1",10,".\images\1.png","",100,.t.,.t.,.f.,.t.,1 }, ;
{ "0002","Sdraio","ser2",10,".\images\2.png","",100,.t.,.t.,.f.,.t.,2 }, ;
{ "0003","Regista","ser3",10,".\images\3.png","",100,.t.,.t.,.f.,.t.,3 }, ;
{ "0004","Parcheggio","parcheggio",10,".\images\4.png","",100,.t.,.t.,.f.,.t.,4 }, ;
{ "0005","Lettino+sdrario+regista","ser5",18,".\images\5.png","[lettino][sdraio][regista]",0,.t.,.t.,.t.,.t.,5 }, ;
{ "0006","sdrario+lettino","ser6",12,".\images\6.png","[sdraio][lettino]",0,.t.,.t.,.t.,.t.,6 }, ;
{ "0007","regista+lettino","ser7",16,".\images\7.png","[regista][lettino]",0,.t.,.t.,.t.,.t.,7 } }


   oDbf  := TDatabase():Create( "SERVIZI.DBF", aCols, "DBFCDX", "*" )
   oDbf:ArrayToDbf( aData )
   oDbf:Close()

RETURN NIL
 
Regards

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

Re: to Nages : probl..FW_ArrayToDbf with tdatabase - RESOLVED!!

Postby Silvio.Falconi » Wed Jan 30, 2019 8:59 pm

THANKS

But on Xbrowse no need the command

:SetoDbf(oServizi)
???

why you rem ordine field from cSwapFields ?

Problem ....when you add a record the field ORDINE IS ZERO , then if you move it up ( 1 step) the number is 7 but the last record have the field ordine zero....


Image
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 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
User avatar
Silvio.Falconi
 
Posts: 7061
Joined: Thu Oct 18, 2012 7:17 pm

Re: to Nages : probl..FW_ArrayToDbf with tdatabase - RESOLVED!!

Postby nageswaragunupudi » Thu Jan 31, 2019 4:32 am

But on Xbrowse no need the command

:SetoDbf(oServizi) ???

You should NOT.
In the XBROWSE command we state "DATASOURCE oServizi". XBrowse automatically sets SetOdbf(). We should not again do it.
why you rem ordine field from cSwapFields ?

This is to demonstrate that only the fields listed in cSwapFields are swapped. The fields not included in the list are not swapped. You decide whether to include ordine also in the list. If you include ordine in the list, ordine field also is swapped.

Note: AutoInc fields are never swapped.

Problem ....when you add a record the field ORDINE IS ZERO

I revised the program. Please test the revised program.
Regards

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

Re: to Nages : probl..FW_ArrayToDbf with tdatabase - RESOLVED!!

Postby Silvio.Falconi » Thu Jan 31, 2019 8:24 am

nageswaragunupudi wrote:
But on Xbrowse no need the command

:SetoDbf(oServizi) ???

You should NOT.
In the XBROWSE command we state "DATASOURCE oServizi". XBrowse automatically sets SetOdbf(). We should not again do it.
why you rem ordine field from cSwapFields ?

This is to demonstrate that only the fields listed in cSwapFields are swapped. The fields not included in the list are not swapped. You decide whether to include ordine also in the list. If you include ordine in the list, ordine field also is swapped.

Note: AutoInc fields are never swapped.

Problem ....when you add a record the field ORDINE IS ZERO

I revised the program. Please test the revised program.



The first time I tried with James to convert my sources with the Tdata class, James and I found that xbrowse did not work well, ie did not display all the required fields, and we arrived at this solution
Sample:

Code: Select all  Expand view
oServiziSingoli:= TServizi():new()
   oServiziSingoli:setFilter( cFilter1)
   oServiziSingoli:gotop()
 cAlias1:= oServiziSingoli:cAlias

@ 95, 40 XBROWSE oBrw1 SIZE 400,-65 PIXEL OF oDlgServizi  ;
         COLUMNS 5,2,4,7,8,9,12,11;
      HEADERS "Tipo","Descrizione","Costo","Disp.","A4", "Pos", "Ord.","";
      COLSIZES 40,110,50,50,28,28,30,34 ;
      CELL LINES NOBORDER ;
      ALIAS cAlias1 //oServiziSingoli:cAlias (Can't use this)
 WITH OBJECT oBrw1
      :nRowHeight    := 30
 :lHscroll            := .F.
      :l2007               := .F.
      :l2015               := .T.
      :lRecordSelector     := .f.
      :nStretchCol         := STRETCHCOL_WIDEST
      :lAllowRowSizing     := .F.
      :lAllowColSwapping   := .F.
      :lAllowColHiding     := .F.
      :nMarqueeStyle       := MARQSTYLE_HIGHLWIN7
      :SetoDBF( oServiziSingoli )
      :CreateFromCode()

   END
 


Now every time I create an xbrowse with tdata, James recommends that I insert the command ": setodbf (oDbf)"


Changing your test and Inserting the columns I wish show (5 and 2) the xbrowse not run ok

@ 70,20 XBROWSE oBrw SIZE -20,-20 PIXEL OF oDlg ;
COLUMNS 5,2 ;
HEADERS "Service","Desc"
;
DATASOURCE oServizi AUTOCOLS ;
LINES NOBORDER

I need to insert DATASOURCE oServizi:cAlias to show the fields
and then make error when I click up and down
Code: Select all  Expand view
Application
===========
   Path and name: C:\Work\Errori\Nages_ordine_tdatabase\test.Exe (32 bits)
   Size: 3,875,840 bytes
   Compiler version: Harbour 3.2.0dev (r1712141320)
   FiveWin  version: FWH 18.10
   C compiler version: Borland/Embarcadero C++ 7.3 (32-bit)
   Windows version: 6.1, Build 7601 Service Pack 1

   Time from start: 0 hours 0 mins 6 secs
   Error occurred at: 01/31/19, 09:44:29
   Error description: Error BASE/1004  No exported method: SKIP
   Args:
     [   1] = U  
     [   2] = N   -1

Stack Calls
===========
   Called from:  => SKIP( 0 )
   Called from: test.prg => SWAPREC( 71 )
   Called from: test.prg => (b)MAIN( 53 )
   Called from: .\source\classes\BUTTON.PRG => TBUTTON:CLICK( 179 )
   Called from: .\source\classes\CONTROL.PRG => TBUTTON:HANDLEEVENT( 1755 )
   Called from: .\source\classes\WINDOW.PRG => _FWH( 3541 )
   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( 1136 )
   Called from:  => DIALOGBOXINDIRECT( 0 )
   Called from: .\source\classes\DIALOG.PRG => TDIALOG:ACTIVATE( 304 )
   Called from: test.prg => MAIN( 58 )


if I add :setodbf(oServizi) run ok

any solution please
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 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
User avatar
Silvio.Falconi
 
Posts: 7061
Joined: Thu Oct 18, 2012 7:17 pm

Re: to Nages : probl..FW_ArrayToDbf with tdatabase - RESOLVED!!

Postby nageswaragunupudi » Thu Jan 31, 2019 1:29 pm

Use DATASOURCE oServizi
Do no use DATASOURCE oServizi:cAlias

With COLUMNS clause never use field numbers. Use only field names

Do not again use :SetODbf()

Do not use COLUMNS clause and also AUTOCOLS. Both are mutually exclusive.

WRONG:
Code: Select all  Expand view

@ 70,20 XBROWSE oBrw SIZE -20,-20 PIXEL OF oDlg ;
COLUMNS 5,2 ;
HEADERS "Service","Desc" ;
DATASOURCE oServizi AUTOCOLS ;
LINES NOBORDER
 


CORRECT:
Code: Select all  Expand view

@ 70,20 XBROWSE oBrw SIZE -20,-20 PIXEL OF oDlg ;
COLUMNS "IMAGE", "NAME" ;
HEADERS "Service","Desc" ;
DATASOURCE oServizi ;
LINES NOBORDER
 


Please remove :SetODbf(...)

You will get errors if you do not use the command the correct way
Regards

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

Re: to Nages : probl..FW_ArrayToDbf with tdatabase - RESOLVED!!

Postby Silvio.Falconi » Thu Jan 31, 2019 11:29 pm

Thanks
I remember i inserted allways numbers with columns command in past
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 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
User avatar
Silvio.Falconi
 
Posts: 7061
Joined: Thu Oct 18, 2012 7:17 pm

Previous

Return to FiveWin for Harbour/xHarbour

Who is online

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