Xbrowse Tree erro with array (sorted out) resolvido

Xbrowse Tree erro with array (sorted out) resolvido

Postby augustogomes » Wed Jun 07, 2017 8:10 pm

Dear friends.

I need to open multiple windows with xbrowse tree with different arrays.
I made a program based on the testxbr3.prg sample. But replacing ADO with an array, I do xbrowse and it's cool, but if I close xbrowse and open again, or open multiple xbrowses, even with different data, they are losing the position of the first column item.
Also misses the font.

It is as if he did not finish xbrowse, his resources remained in the memory.
I do not know if I'm doing it right, or if I have another way.

I have prepared an example source.

Below the pictures when you open the first time and change with each opening of the xbrowse.
I have already tested with WINDOWS and DIALOG and the result is the same.

Picture 1
https://photos.google.com/photo/AF1QipNWHa2xTocTxSiamqyH4V6p46b3SEgnbcGRLkz3
picture 2
https://photos.google.com/photo/AF1QipPB1oKjixaRjv5Uzj33CkLiLRxsNVhzlRnm5g8g
pict 3
https://photos.google.com/photo/AF1QipPeD5m4-eXDJYZ0-kTOkZM8bmJvlY0hkPzMthtq
pict 4
https://photos.google.com/photo/AF1QipOaM_hvilAJXjD7ZT7-zR8V7fkm-FdrwklJDCAT

source
Code: Select all  Expand view  RUN

#include "FiveWin.ch"
#include "xBrowse.ch"

#xtranslate :CODGRU  => \[01]
#xtranslate :NOMGRU  => \[02]
#xtranslate :CODMAT  => \[03]
#xtranslate :NOMMAT  => \[04]
#xtranslate :QTDMAT  => \[05]
#xtranslate :VALMAT  => \[06]
#xtranslate :CODEMP  => \[07]
#xtranslate :NOMEMP  => \[08]                          
#xtranslate :QTDEMP  => \[09]
#xtranslate :VALEMP  => \[10]
#xtranslate :NROPED  => \[11]
#xtranslate :TIPDOC  => \[12]
#xtranslate :VALGRU  => \[13]
#xtranslate :QTDGRU  => \[14]
#xtranslate :FATGRU  => \[15]
#xtranslate :PERGRU  => \[16]
#xtranslate :INDPER  => \[17]
#xtranslate :FATMAT  => \[18]
#xtranslate :FATEMP  => \[19]
#xtranslate :TOTMES  => \[20]

FUNCTION xbrtree1()
private oFntB12
           
        I_Tela( )

RETURN

Static Function I_Tela()

local oBtn,oDlgPesq,alVen:={}
 
 for klcont:=1 to 9
      aAdd( alVen,;
        {"PA12","2 - Suprimentos","120010"+str(klcont,1),"CABO LAPLINK M"+str(klcont,1),9.000000,3894.000000000000,"4001505","WESLEY RIBEIRO ANTUNES",1.000,3894.000000000000,"4000","PEDIDO",5130.743243,120.000000,3894.0000,58.49,1.000000,0,0,8771.300000})
 next       
 
 for klcont:=1 to 9
      aAdd( alVen,;
        {"PA11","1 - Equipamento","110086"+str(klcont,1),"CALCULADORA CASIO"+str(klcont,1),15.000000,1946.756756756757,"1000014","3 STAR INFORMATICA LTDA",15.000,1946.756756756757,"3982","PEDIDO",4489.556757,28.000000,98.0000,51.18,1.324324,0,0,8771.300000})

 next       
 DEFINE FONT oFntB12 NAME "Arial" SIZE 0,-12 ITALIC BOLD
 
 DEFINE DIALOG oDlgPesq TITLE "Pesquisa de ";
    FROM  14,  34 TO  45, 135 STYLE nOr(WS_POPUP,DS_MODALFRAME,WS_CAPTION,WS_VISIBLE)

   
   @ 02,20 say "testes" size 40,08 of oDlgPesq
    @ 60,20 BUTTONBMP oBtn SIZE 26,26 ACTION I_CriaBrowse("teste","FAT", 1,alVen) OF oDlgPesq PROMPT "Xbrowse" BITMAP "NEW"  PIXEL    TEXTBOTTOM CANCEL
   
   ACTIVATE DIALOG oDlgPesq CENTERED ON init BtnBarDlg( oDlgPesq,alVen )  
   

return .T.
//----------------------------------------------------------------------------//
*
* support functions
*
//----------------------------------------------------------------------------//

static function BtnBarDlg( oDlgPesq,alVen )

   local oBar, oBtn

 DEFINE BUTTONBAR oBar OF oDlgPesq SIZE 56,64 2015
     
 DEFINE BUTTON OF oBar ;
      RESOURCE "NEW" TOP NOBORDER ;
      PROMPT "XBrowse" TOOLTIP "Abre uma nota tela xbrowse" ;
      MESSAGE "Abre uma nota tela xbrowse" ;
       ACTION ( I_CriaBrowse("teste","FAT", 1,alVen) )
 
   DEFINE BUTTON oBtn OF oBar GROUP ;
      RESOURCE "CLOSE2" TOP NOBORDER PROMPT "Close" ;
      ACTION ( oDlgPesq:End()) ;
      MESSAGE "Fecha Dialog" ;
      TOOLTIP "Fecha Dialog"
     
    SET MESSAGE OF oDlgPesq TO "Testing XBrowse" 2007
   
return oBar

Static Function  I_CriaBrowse(clTitulo,clVar, clTipTree,alArray)

 local oBrw,klcont
 
 if len(alArray)=0
    return .f.
 endif
 
    DEFINE WINDOW oWnd FROM  14,  34 TO  45, 135  TITLE "TESTES XbrTree - AUGUSTO"
    // oWnd:SetFont( oFntB12 )
    //  RELEASE FONT oFntB10
                               
    @ 40,02 XBROWSE oBrw OF oWnd SIZE 392,162 PIXEL LINES CELL DATASOURCE BuildTree1(clVar, clTipTree,alArray)   ;
          COLUMNS 1,2,3,4,5,6,7 HEADERS "Descrição","Quantidade", "Valor","% Fat","% Grupo","% Total","Documento";
          PICTURES nil, "99999999999.999", "@E 999,999,999.99",nil,"@E 999.99%","@E 999.99%","@!"  ;
          FOOTERS AUTOSORT
   
    oBrw:nMarqueeStyle    := MARQSTYLE_HIGHLROW  
   oBrw:nStretchCol   := 1  
    oBrw:aCols[ 1 ]:AddBitmap( { "OPEN", "CLOSE", "GREEN" }  )
    oBrw:aCols[2]:cFooter       := "Total"
    oBrw:aCols[ 3 ]:nFooterType    := AGGR_SUM
    oBrw:aCols[ 5 ]:nFooterType    := AGGR_SUM
    oBrw:aCols[ 6 ]:nFooterType    := AGGR_SUM
     
     // AEval( oBrw:aCols, { |oCol| oCol:oDataFont := { || If( oBrw:oTreeItem:nLevel == 1, oFntB12, oBrw:oFont ) } } )
    //AEval( oBrw:aCols, { |oCol| oCol:oFooterFont := oFntB12 } )
   
    WITH OBJECT oBrw
       :oDataFonts    := { || If( oBrw:oTreeItem:nLevel == 1, oFntB12, oBrw:oFont ) }
       :oFooterFonts    := oFntB12
       :createFromCode()
    END
   
    oBrw:aCols[ 8 ]:Hide()
   
    IF  clTipTree <> 3
        oBrw:aCols[ 4 ]:Hide()
    ENDIF
     
   
    oWnd:oClient = oBrw
   
    BtnBarWnd( oBrw,oWnd )    // Commn ButtonBar for all sample Browses
    oBrw:MakeTotals()   
   
    DEFINE BUTTON OF oWnd:oBar ;
       RESOURCE "EXPAND" TOP PROMPT "Expande" ;
       ACTION ( oBrw:oTree:Expand(), oBrw:Refresh(), oBrw:SetFocus() )
   
    DEFINE BUTTON OF oWnd:oBar ;
       RESOURCE "COLLAPS" TOP PROMPT "Comprime" ;
       ACTION ( oBrw:oTree:Collapse(), oBrw:Refresh(), oBrw:SetFocus() )
       
     
    SET MESSAGE OF oWnd TO "Testando XBrowse" 2015
    ACTIVATE WINDOW oWnd ON INIT oBrw:SetFocus()
   
         
Return .t.  

static function BtnBarWnd( oBrw,oWnd )

   local oBar, oBtn

   DEFINE BUTTONBAR oBar OF oBrw:oWnd SIZE 56,64 2007
   DEFINE BUTTON OF oBar ;
      RESOURCE "REPORT" TOP NOBORDER ;
      PROMPT "Report" ;
      MENU ReportMenu( oBrw ) ;
      ACTION This:ShowPopUp() ;
      MESSAGE "Print the browse contents" ;
      TOOLTIP { "Print Report", "Report" }

   DEFINE BUTTON OF oBar ;
      RESOURCE "PDF" TOP NOBORDER ;
      PROMPT "PDF" ;
      MENU PdfMenu( oBrw ) ;
      ACTION This:ShowPopUp() ;
      MESSAGE "Save browse contents to PDF" ;
      TOOLTIP { "Save Report", "to PDF" }

   DEFINE BUTTON OF oBar ;
      RESOURCE "EXCEL" TOP NOBORDER ;
      PROMPT "Excel" ;
      ACTION This:ShowPopUp() ;
      MENU ExcelMenu( oBrw ) ;
      MESSAGE "Export browse contents to Excel" ;
      TOOLTIP { "Export to Excel", "Excel" }
         
   DEFINE BUTTON OF oBar ;
      RESOURCE 'FIND' TOP NOBORDER PROMPT 'Inspect' ;
      ACTION XBrowse( oBrw ) ;
      TOOLTIP 'Browse Variables' + CRLF + 'of Browse Object'

   DEFINE BUTTON OF oBar ;
      RESOURCE 'ARRAY' TOP NOBORDER PROMPT 'Hash' ;
      ACTION HashBrowse( oBrw ) ;
      TOOLTIP 'HashBrowse' + CRLF + 'CurrentRow'
     
   DEFINE BUTTON oBtn OF oBar GROUP ;
      RESOURCE "CLOSE2" TOP NOBORDER PROMPT "Close" ;
      ACTION (  oBrw:oWnd:End()) ;
      MESSAGE "Close Window" ;
      TOOLTIP "Close Window"

return oBar
//----------------------------------------------------------------------------//

static function HashBrowse( oBrw )

   local hData    := {=>}
   local oCol


   HSetAACompatibility( hData, .t. )
   for each oCol in oBrw:aCols
      HSet( hData, oCol:cHeader, oCol:Value )
   next


   xBrowse( hData, 'Hash Browse' )

return nil
//----------------------------------------------------------------------------//

static function PdfMenu( oBrw )

   local oPop

   MENU oPop POPUP 2007
      MENUITEM "Simple Report" ACTION oBrw:Report( nil, .t., nil, nil, nil, "pdf" )
      MENUITEM "Report with Grouping" ;
         WHEN ! Empty( oBrw:GetVisibleCols()[1]:cOrder ) ;
         ACTION oBrw:Report( nil, .t., .f., nil, 1, "pdf" )
   ENDMENU

return oPop

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

static function ReportMenu( oBrw )

   local oPop

   MENU oPop POPUP 2007
      MENUITEM "Simple Report" ACTION oBrw:Report()
      MENUITEM "Report with Grouping" ;
         WHEN ! Empty( oBrw:GetVisibleCols()[1]:cOrder ) ;
         ACTION oBrw:Report( nil, .t., .t., nil, 1 )
   ENDMENU

return oPop

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

static function ExcelMenu( oBrw )

   local oPop

   MENU oPop POPUP 2007
      MENUITEM "Export to Excel" ACTION oBrw:ToExcel()
      MENUITEM "Export to Excel with Group Totals" ;
         WHEN ! Empty( oBrw:GetVisibleCols()[1]:cOrder ) ;
         ACTION oBrw:ToExcel()
   ENDMENU

return oPop

static function BuildTree1(clVar, clTipo,alArray)
local klCont:=0
local oTree, clGruGeral:=space(15), clCodMat := spac(7) , clCodEmp , nlTotal :=0

if clVar= "FAT"
   nlTotal:= 8771.30
endif      

if clTipo=1
    alArray := ASORT(alArray,,,{ |x, y| str(x[13])+x[02]+str(x[06]) > str(y[13])+y[2]+str(y[06]) })  
   
    TREE oTree
        for klcont:=1 to len(alArray)
                             
            if Empty( clGruGeral )
                TREEITEM alArray[klCont]:NomGru CARGO {alArray[klCont]:QtdGru,;
                                                  alArray[klCont]:ValGru,;
                                                    0,             ;
                                                  (alArray[klCont]:ValGru / nlTotal) * 100 ,;
                                                  (alArray[klCont]:ValGru / nlTotal) * 100,;
                                                  alArray[klCont]:CodGru,;
                                                  "GRUPO"}
                           
                TREE
               clGruGeral = alArray[klCont]:NomGru
            else
               if clGruGeral != alArray[klCont]:NomGru
                  ENDTREE
                  clGruGeral = alArray[klCont]:NomGru
                    TREEITEM alArray[klCont]:NomGru CARGO {alArray[klCont]:QtdGru,;
                                                      alArray[klCont]:ValGru,;
                                                        0,             ;
                                                      (alArray[klCont]:ValGru / nlTotal) * 100 ,;
                                                      (alArray[klCont]:ValGru / nlTotal) * 100,;
                                                      alArray[klCont]:CodGru,;
                                                      "GRUPO"}
                   
                    TREE
               endif  
            endif  
           
           if alArray[klCont]:NomGru== clGruGeral
           
                IF alArray[klCont]:CodMat # clCodMat
               
                    TREEITEM alArray[klCont]:NomMat CARGO { alArray[klCont]:QtdMat,;
                                                alArray[klCont]:ValMat,;
                                                                       0,;
                                            (alArray[klCont]:ValMat / alArray[ klcont]:ValGru) * 100   ,;
                                            (alArray[klCont]:ValMat / nlTotal ) * 100   ,;
                                             alArray[klCont]:CodMat,;              
                                                              "GRUPO"}
                   
                    TREE oSubTree
                    clCodMat := alArray[klCont]:CodMat
               
                endif
                                                                                                                               
                 TREEITEM alArray[klCont]:NomEmp CARGO {alArray[klCont]:QtdEmp,;
                                              alArray[klCont]:ValEmp,;
                                               0,;
                                             (alArray[klCont]:ValEmp / alArray[ klcont]:ValMat) * 100   ,;
                                             (alArray[klCont]:ValEmp / nlTotal ) * 100   ,;
                                             alArray[klCont]:NroPed,;
                                             alArray[klCont]:TipDoc }
            endif
               
           IF klCont+1<=len(alArray)
                if alArray[klCont+1]:CodMat # clCodMat
                        ENDTREE
              endif         
            endif
        next
           ENDTREE
         
       ENDTREE
   
endif      

return oTree
 
Last edited by augustogomes on Thu Jun 08, 2017 6:28 pm, edited 1 time in total.
Augusto Gomes /Suprisystem Informática - Fivewin 16.08 - xharbour 123 - BCC70 - DBFNTX e PostGreSql
User avatar
augustogomes
 
Posts: 23
Joined: Mon Jun 06, 2016 8:38 pm
Location: Ribeirão Preto - SP - Brasil

Re: Xbrowse Tree erro with array

Postby nageswaragunupudi » Thu Jun 08, 2017 12:21 am

TREE/ENDTREE did not match.

Please add one more ENDTREE just before the last "endif"
Regards

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

Re: Xbrowse Tree erro with array

Postby augustogomes » Thu Jun 08, 2017 6:27 pm

nageswaragunupudi

Many thanks for the reply.
That's right, I spent a week trying to find the problem and did not realize it.

Once again.
Thank you!
Augusto Gomes /Suprisystem Informática - Fivewin 16.08 - xharbour 123 - BCC70 - DBFNTX e PostGreSql
User avatar
augustogomes
 
Posts: 23
Joined: Mon Jun 06, 2016 8:38 pm
Location: Ribeirão Preto - SP - Brasil


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Danielmaximiliano, Google [Bot] and 45 guests