I saw ...
the Exec Method run also with tdata
I wish resolve the problem of these function
dbfToArray
ArrayToDBF
do you remember the test where I need to make an order and move the record to another position ?
With tdata I have problems ( not run) but It not run also with tdatabase
as you can see on the picture the "Ombrellone " on first xbrowse is on the first position
on xbrowse num. 2 ( big) I move the record to end but the field ELOrdine is not changed
if I move a line he had to change the number and instead he has never changed
always remaining 1
Version for tdatabase
this is the code ( with tdatabase)
Code: Select all
#include "fivewin.ch"
REQUEST DBFCDX
static cPath
Function test()
Local oDlg,oElementi,oGrid
Local aBrowse
cPath := cFilePath(GetModuleFileName( GetInstance() )) + "Data\"
oElementi := TDatabase():Open( ,cPath+ "ELEMENTI", "DBFCDX", .T. )
oElementi:SetOrder( 1 )
oElementi:GoTop()
DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-12
DEFINE DIALOG oDlg SIZE 400, 280 PIXEL;
FONT oFont TITLE "Elements"
aBrowse := { { "ELATTIVO", i18n("Attivo"),, 80, },;
{ "ELNOME", i18n("Descrizione elemento"),, 80, },;
{ "", i18n("Colore "),, 80, },;
{ "ELCOLORE", i18n("Descr. Colore"),, 80, },;
{ "ELORDINE", i18n("Ordine"),, 80, },;
{ "ELLOCK", i18n("Bloccato"),, 200,} }
@0,5 XBROWSE oGrid ;
SIZE 180,100 PIXEL;
OF oDlg ;
DATASOURCE oElementi COLUMNS aBrowse
WITH OBJECT oGrid
:nClrBorder := CLR_GRAY
:nMarqueeStyle := MARQSTYLE_HIGHLWIN7
:lHscroll := .F.
:l2007 := .F.
:l2015 := .T.
:nStretchCol := STRETCHCOL_WIDEST
:lAllowRowSizing := .F.
:lAllowColSwapping := .F.
:lAllowColHiding := .F.
:lRecordSelector := .F.
:nColDividerStyle := LINESTYLE_LIGHTGRAY
:nRowDividerStyle := LINESTYLE_LIGHTGRAY
:nRowDividerStyle := LINESTYLE_NOLINES
:nColDividerStyle := LINESTYLE_LIGHTGRAY
:CreateFromCode()
END
@ 112,2 BTNBMP PROMPT "Order" SIZE 40,20 LEFT PIXEL OF oDlg ;
ACTION Ordine_Elementi(oGrid,oElementi)
activate dialog oDlg
return nil
//----------------------------------------------------------------------------//
function Ordine_Elementi(oGrid,oElementi)
local oDlg, oBrw, oFont
local cSwapFields:="ELNUMERO,ELORDINE,ELNOME,ELCOLORE,ELATTIVO,ELIMGLIB,ELIMGOCC,ELIMGALT,ELLOCK"
oElementi:setorder(0)
oElementi:gotop()
DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-12
DEFINE DIALOG oDlg SIZE 900,300 PIXEL TRUEPIXEL FONT oFont;
TITLE "ELEMENTI.DBF"
@ 70,20 XBROWSE oBrw SIZE -20,-20 PIXEL OF oDlg ;
DATASOURCE oElementi 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:SetDefault( "ELORDINE", { || oBrw:oDbf:LastRec() + 1 }, .F. )
oRec:Edit()
return nil
//-----------------------------------------------------------------------------------------------//
Function BuildDbf()
field ID,NAME,ORDINE
local oDbf
local aCols := { ;
{ "ELNUMERO" , "C", 2, 0 },; //NUMERO
{ "ELORDINE" , "N", 2, 0 },; //ORDINE
{ "ELNOME" , "C", 30, 0 },;
{ "ELCOLORE" , "C", 30, 0 },;
{ "ELATTIVO" , "L", 1, 0 },;
{ "ELIMGLIB" , "C", 120, 0 },;
{ "ELIMGOCC" , "C", 120, 0 },;
{ "ELIMGALT" , "C", 120, 0 },;
{ "ELLOCK" , "L", 1, 0 }}
Local aData := { ;
{"01",1,"OMBRELLONE","lightgreen",.T.,".\images\ombrellone_verde.png",".\images\ombrelloneOccupato.png",".\images\ombrellone_bianco.png",.T.}, ;
{"02",2,"PALMA","red",.T.,".\images\palma.png",".\images\palmaOccupato.png",".\images\palma_arancio.png",.T.}, ;
{"03",3,"CABINA","thistle",.T.,".\images\cabina.png",".\images\cabinaOccupato.png",".\images\cabina_arancio.png",.T.}, ;
{"04",4,"TENDA","coral",.T.,".\images\tenda.png",".\images\tendaOccupato.png",".\images\tenda_blue.png",.T.}, ;
{"05",5,"BIDONE","gainsboro",.F.,".\images\bidone.png","","",.T. }, ;
{"06",6,"PASSERELLA A INCROCIO","burlywood",.F.,".\images\passerella_incrocio.png","","",.T. }, ;
{"07",7,"PASSERELLA A L","cadetblue",.F.,".\images\passerella_L.png","","",.T. }, ;
{"08",8,"PASSERELLA L DESTRA","darkgoldenrod",.F.,".\images\passerella_L_destra.png","","",.T.}, ;
{"09",9,"PASSERELLA L SINISTRA","darkturquoise",.F.,".\images\passerella_L_sinistra.png","","",.T. }, ;
{"10",10,"PASSERELLA L SOPRA","gold",.F.,".\images\passerella_L_sopra.png","","",.T. }, ;
{"11",11,"PASSERELLA ORIZONTALE","whitesmoke",.F.,".\images\passerella_orizzontale.png","","",.T. }, ;
{"12",12,"PASSERELLA A T SOPRA","deepskyblue",.F.,".\images\passerella_T_sopra.png","","",.T. }, ;
{"13",13,"PASSERELLA A T SOTTO","deepskyblue",.F.,".\images\passerella_T_sotto.png","","",.T. }, ;
{"14",14,"PASSERELLA VERTICALE","firebrick",.F.,".\images\passerella_verticale.png","","",.T.}, ;
{"15",15,"PALMA ORNAMENTALE","darkkhaki",.F.,".\images\palmaC.png","","",.T. }, ;
{"16",16,"GIOCHI","turquoise",.F.,".\images\giochi.png","","",.T. }, ;
{"17",17,"BAGNINO","darkorchid",.F.,".\images\torretta.png","","",.T.}}
oDbf := TDatabase():Create(cPath+ "ELEMENTI.DBF", aCols, "DBFCDX", "*" )
oDbf:ArrayToDbf( aData )
oDbf:Close()
RETURN NIL
//-----------------------------------------------------------------------------------//
Version for Tdata
this is the source code of the test ( but need tdata class)
Code: Select all
#include "fivewin.ch"
REQUEST DBFCDX
Function test()
Local oDlg,oElementi,oGrid
Local aBrowse
BuildDbf()
oElementi:=TElementi():New()
oElementi:setorder(1)
oElementi:gotop()
DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-12
DEFINE DIALOG oDlg SIZE 400, 280 PIXEL;
FONT oFont TITLE "Elements"
aBrowse := { { "ELATTIVO", i18n("Attivo"),, 80, },;
{ "ELNOME", i18n("Descrizione elemento"),, 80, },;
{ "", i18n("Colore "),, 80, },;
{ "ELCOLORE", i18n("Descr. Colore"),, 80, },;
{ "ELORDINE", i18n("Ordine"),, 80, },;
{ "ELLOCK", i18n("Bloccato"),, 200,} }
@0,5 XBROWSE oGrid ;
SIZE 180,100 PIXEL;
OF oDlg ;
DATASOURCE oElementi COLUMNS aBrowse
WITH OBJECT oGrid
:nClrBorder := CLR_GRAY
:nMarqueeStyle := MARQSTYLE_HIGHLWIN7
:lHscroll := .F.
:l2007 := .F.
:l2015 := .T.
:nStretchCol := STRETCHCOL_WIDEST
:lAllowRowSizing := .F.
:lAllowColSwapping := .F.
:lAllowColHiding := .F.
:lRecordSelector := .F.
:nColDividerStyle := LINESTYLE_LIGHTGRAY
:nRowDividerStyle := LINESTYLE_LIGHTGRAY
:nRowDividerStyle := LINESTYLE_NOLINES
:nColDividerStyle := LINESTYLE_LIGHTGRAY
:CreateFromCode()
END
@ 112,2 BTNBMP PROMPT "Order" SIZE 40,20 LEFT PIXEL OF oDlg ;
ACTION Ordine_Elementi(oGrid,oElementi)
activate dialog oDlg
return nil
//----------------------------------------------------------------------------//
function Ordine_Elementi(oGrid,oElementi)
local oDlg, oBrw, oFont
local cSwapFields:="ELNUMERO,ELORDINE,ELNOME,ELCOLORE,ELATTIVO,ELIMGLIB,ELIMGOCC,ELIMGALT,ELLOCK"
oElementi:setorder(0)
oElementi:gotop()
DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-12
DEFINE DIALOG oDlg SIZE 900,300 PIXEL TRUEPIXEL FONT oFont;
TITLE "ELEMENTI.DBF"
@ 70,20 XBROWSE oBrw SIZE -20,-20 PIXEL OF oDlg ;
DATASOURCE oElementi 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:SetDefault( "ELORDINE", { || oBrw:oDbf:LastRec() + 1 }, .F. )
oRec:Edit()
return nil
Function BuildDbf()
field ID,NAME,ORDINE
local oDbf
local aCols := { ;
{ "ELNUMERO" , "C", 2, 0 },; //NUMERO
{ "ELORDINE" , "N", 2, 0 },; //ORDINE
{ "ELNOME" , "C", 30, 0 },;
{ "ELCOLORE" , "C", 30, 0 },;
{ "ELATTIVO" , "L", 1, 0 },;
{ "ELIMGLIB" , "C", 120, 0 },;
{ "ELIMGOCC" , "C", 120, 0 },;
{ "ELIMGALT" , "C", 120, 0 },;
{ "ELLOCK" , "L", 1, 0 }}
Local aData := { ;
{"01",1,"OMBRELLONE","lightgreen",.T.,".\images\ombrellone_verde.png",".\images\ombrelloneOccupato.png",".\images\ombrellone_bianco.png",.T.}, ;
{"02",2,"PALMA","red",.T.,".\images\palma.png",".\images\palmaOccupato.png",".\images\palma_arancio.png",.T.}, ;
{"03",3,"CABINA","thistle",.T.,".\images\cabina.png",".\images\cabinaOccupato.png",".\images\cabina_arancio.png",.T.}, ;
{"04",4,"TENDA","coral",.T.,".\images\tenda.png",".\images\tendaOccupato.png",".\images\tenda_blue.png",.T.}, ;
{"05",5,"BIDONE","gainsboro",.F.,".\images\bidone.png","","",.T. }, ;
{"06",6,"PASSERELLA A INCROCIO","burlywood",.F.,".\images\passerella_incrocio.png","","",.T. }, ;
{"07",7,"PASSERELLA A L","cadetblue",.F.,".\images\passerella_L.png","","",.T. }, ;
{"08",8,"PASSERELLA L DESTRA","darkgoldenrod",.F.,".\images\passerella_L_destra.png","","",.T.}, ;
{"09",9,"PASSERELLA L SINISTRA","darkturquoise",.F.,".\images\passerella_L_sinistra.png","","",.T. }, ;
{"10",10,"PASSERELLA L SOPRA","gold",.F.,".\images\passerella_L_sopra.png","","",.T. }, ;
{"11",11,"PASSERELLA ORIZONTALE","whitesmoke",.F.,".\images\passerella_orizzontale.png","","",.T. }, ;
{"12",12,"PASSERELLA A T SOPRA","deepskyblue",.F.,".\images\passerella_T_sopra.png","","",.T. }, ;
{"13",13,"PASSERELLA A T SOTTO","deepskyblue",.F.,".\images\passerella_T_sotto.png","","",.T. }, ;
{"14",14,"PASSERELLA VERTICALE","firebrick",.F.,".\images\passerella_verticale.png","","",.T.}, ;
{"15",15,"PALMA ORNAMENTALE","darkkhaki",.F.,".\images\palmaC.png","","",.T. }, ;
{"16",16,"GIOCHI","turquoise",.F.,".\images\giochi.png","","",.T. }, ;
{"17",17,"BAGNINO","darkorchid",.F.,".\images\torretta.png","","",.T.}}
Local cPath := cFilePath(GetModuleFileName( GetInstance() )) + "Data\"
oDbf := TDatabase():Create(cPath+ "ELEMENTI.DBF", aCols, "DBFCDX", "*" )
oDbf:ArrayToDbf( aData )
oDbf:Close()
RETURN NIL
//-----------------------------------------------------------------------------------//
CLASS TXData from TData
DATA cPath init cFilePath(GetModuleFileName( GetInstance() )) + "Data\" // just for testing
// DATA cPath init oApp:cDbfPath
ENDCLASS
CLASS TElementi from TXData
METHOD New()
ENDCLASS
METHOD New( lShared ) CLASS TElementi
Default lShared := .t.
::super:New(,::cPath + "Elementi" ,, lShared)
if ::use()
::setOrder(1)
::gotop()
endif
RETURN Self
Where is the error ?