xBrowse con Tdatabase mal en 1307 - Solucionado

xBrowse con Tdatabase mal en 1307 - Solucionado

Postby rolando » Fri Oct 18, 2013 12:59 pm

Buen día,

Tengo un pequeño programa de muestra. Así básicamente uso la xBrowe con la TDatabase:

Code: Select all  Expand view
#INCLUDE "FIVEWIN.Ch"
#include "xbrowse.ch"




#define renglon chr(13) + chr(10)

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

  Function HojearService()


    

   local oBrw , oLbx , lSalir:=.f. , oDbf , oDlg , nAregi , oCol , oRichService , cRichService , oBrush , oFont
     local cService:=cGetNewAlias('Servic') , oBtnAgregar , oBtnGuardar , oBtnBorrar , oBtnSalir , oCur1 , nRecno ,;
                 oBtnProveedor , oBtnFalta , oBtnVAP , oBtnPrint , oBrush2 , oBtnTop , oBtnBot , nOrden , oBtnBorrado ,;
                 cBuscar:="" , oBtnBuscar , oBtnBuscaSele , aDBF:={} , cDato , oClp , cText , Clp , oSayStockNO , oFont2
     local nRecnoInicial:=1 , aArrayPaso , lcBusco:=.f. , nColSele:=0



        REQUEST HB_LANG_ES
        RddSetDefault("DBFCDX")
        REQUEST ordkeyno, ordkeycount, ordkeygoto
        REQUEST DBFCDX, DBFFPT
   

             use "customer" shared new alias (cService)
             DATABASE oDbf

            oDbf:SetOrder( 3, "customer.CDX"  )   // ordeno por APARATO
            nRecnoInicial:=oDbf:RECNO()

     #define fondo1 nrgb(255,255,0)


     define font oFont NAME "Arial" SIZE 6,16 bold
     define font oFont1 NAME "Arial" SIZE 25,45 bold
     define font oFont2 NAME "Arial" SIZE 15,35 bold

     define cursor oCur1 resource 222
     define brush oBrush resource "BEIGE2"
     define brush oBrush2 resource "fondo9" //    "azul"


     define dialog oDlg resource "SERVICE"

     oDlg:lHelpIcon := .f.    

     oDlg:cTitle:="LISTANDO CUSTOMER FWH1307"

     oBrw := TXBrowse():New( oDlg )

                     
         oBrw:nHeaderLines := 1
         oBrw:lFastEdit := .f.  
     oBrw:SetoDbf( oDbf )  
         oBrw:SetBackGround(oBrush2)    
         oBrw:setfont(oFont)
         oBrw:lContrastClr := .f.       // para evitar que los caracteres salgan aleatoriamente con otra tinta
         oBrw:bClrSel      := {|| { nRGB(  255,  255,255), nRGB(144,196,205) } }  // para barra de linea selecc cuando el control no tiene el foco
     oBrw:oCursor:=oCur1
         oBrw:nHeaderHeight:=21.90
         oBrw:bGotFocus:={||dbSelectArea(cService) }

            oCol                                := oBrw:AddCol()
            oCol:cHeader        := "NOMBRE"
            oCol:bStrData       := { || oDbf:FIRST }
            oCol:nHeadStrAlign  := AL_CENTER
            oCol:nDataStrAlign  := AL_LEFT
            oCol:nWidth         := 130
            oCol:cSortOrder         := "FIRST"
          oBrw:aCols[ 1 ]:nEditType := EDIT_GET
            oBrw:aCols[ 1 ]:bOnPostEdit := {|oCol, xVal, nKey| iif( nKey != VK_ESCAPE, ;
                            (oDbf:FIRST:=upper(xVal) , oDbf:save() , oBrw:refresh() ) , ) }
            oBrw:aCols[1]:cEditPicture := "@!"
            oBrw:aCols[1]:cTooltip:="Clickear una vez con el izquierdo para ordenar por NOMBRE"
 


                                            //-----------------------------------------//
            oCol                                := oBrw:AddCol()
            oCol:cHeader        := "APELLIDO"
            oCol:bStrData       := { || oDbf:LAST }
            oCol:nHeadStrAlign  := AL_CENTER
            oCol:nDataStrAlign  := AL_LEFT
            oCol:nWidth         := 160
            oCol:cSortOrder         := "LAST"
          oBrw:aCols[ 2 ]:nEditType := EDIT_GET    
            oBrw:aCols[ 2 ]:bOnPostEdit := {|oCol, xVal, nKey| iif( nKey != VK_ESCAPE, ;
                            (oDbf:LAST:=xVal , oDbf:save() , oBrw:refresh() ) , ) }
            oBrw:aCols[2]:cEditPicture := "@!"
            oBrw:aCols[2]:cTooltip:="Clickear una vez con el izquierdo para ordenar por APELLIDO"

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

                                            //-----------------------------------------//
            oCol                                := oBrw:AddCol()
            oCol:cHeader        := "CALLE"
            oCol:bStrData       := { || oDbf:STREET }
            oCol:nHeadStrAlign  := AL_CENTER
            oCol:nDataStrAlign  := AL_LEFT
            oCol:nWidth         := 230
            oCol:cSortOrder         := "STREET"
          oBrw:aCols[ 3 ]:nEditType := EDIT_GET    
            oBrw:aCols[ 3 ]:bOnPostEdit := {|oCol, xVal, nKey| iif( nKey != VK_ESCAPE, ;
                            (oDbf:STREET:=xVal , oDbf:save() , oBrw:refresh() ) , ) }
            oBrw:aCols[3]:cEditPicture := "@!"
            oBrw:aCols[3]:cTooltip:="Clickear una vez con el izquierdo para ordenar por CALLE"

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

       

            oBrw:nStretchCol:=STRETCHCOL_LAST

 
            oBrw:nRowHeight:=20.90             // alto de linea, variarlo para dejar que encaje casi casi en el listbox

            oBrw:nRowDividerStyle := LINESTYLE_LIGHTGRAY
            oBrw:nColDividerStyle := LINESTYLE_LIGHTGRAY
            oBrw:nMarqueeStyle := MARQSTYLE_HIGHLCELL //MARQSTYLE_HIGHLROW
            oBrw:lHScroll:=.t.

            oBrw:lAllowRowSizing     := .F.       // no permite que agrande las líneas

           


                oBrw:bClrSel:={||{nRGB(255,255,255), nRGB(144,196,205)}}

           
            oBrw:CreateFromResource( 4001 )

  oDlg:bPainted:={ ||dbSelectArea(cService) }


    oDlg:bStart:={|| oDlg:setfocus() }

    ACTIVATE DIALOG oDlg on init (oDbf:GOTO(nRecnoInicial));
                         valid (oDbf:close() , .t.)

    oFont:end()
    oFont1:end()
    oFont2:end()
    oBrush:end()
   

 return nil


Siempre compiló y funcionó bien, pero ahora con la versión 1307 hace un problema que puede verse en la imagen que adjunto y es que agrega una columna vacía al xBrowse con el dato "EMPTY COL". Obviamente que busqué en la clase y tiene bastante reforma para esto pero se me ocurre que ESTOY HACIENDO ALGO MAL Y DEBIERA USAR LA XBROWSE DE OTRA MANERA Y DE AHÍ VENGA LA FALLA.

Image

También subí un video en el que puede verse el mismo prg compilado con la 1302 y después compilado con la 1307. Con la 1302 no presenta falla, ordena al presionar sobre cabeceras y NO AGREGA UNA COLUMNA.

Luego puede verse el mismo PRG pero compilado con la 1307 y ahí el problema.

http://youtu.be/v5GRh4FGxdE

¿Alguna ayuda?. Gracias.

Rolando :D
Last edited by rolando on Sun Oct 20, 2013 3:35 am, edited 4 times in total.
User avatar
rolando
 
Posts: 593
Joined: Sat May 12, 2007 11:47 am
Location: San Nicolás - BA - ARGENTINA

Re: xBrowse con Tdatabase mal en 1307

Postby nageswaragunupudi » Sat Oct 19, 2013 1:51 am

Please call oBrw:SetBackGround(...) after defining all the columns.
Regards

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

Re: xBrowse con Tdatabase mal en 1307

Postby nageswaragunupudi » Sat Oct 19, 2013 5:28 am

The above style of coding does not allow taking full advantage of all the features of xbrowse.

This is the recommended way of coding:
Code: Select all  Expand view
#include "fivewin.ch"
#include "ord.ch"
#include "xbrowse.ch"

REQUEST DBFCDX

function Main()

   local oDbf, oDlg, oFont, oBrw

   oDbf  := TDataBase():Open( nil, "CUSTOMER", "DBFCDX", .t. )
   oDbf:SetOrder( "STREET" )

   DEFINE FONT oFont NAME "Arial" SIZE 6,16
   DEFINE DIALOG oDlg RESOURCE "DIALOG_1" FONT oFont ;
      TITLE "LISTANDO CUSTOMER " + FWVERSION

   REDEFINE XBROWSE oBrw ID 101 DATASOURCE oDbf ;
      COLUMNS "FIRST", "LAST", "STREET" ;
      HEADERS "NOMBRE", "APELLIDO", "KALLE" ;
      PICTURES "@!", "@!", "@!" ;
      COLSIZES 130,130,160 ;
      AUTOSORT CELL LINES ;
      BACKGROUND "c:\fwh\bitmaps\backgrnd\stone.bmp"

   WITH OBJECT oBrw
      :nEditTypes       := EDIT_GET
      :nHeadStrAligns   := AL_CENTER
      :nStretchCol      := STRETCHCOL_WIDEST
      :nColDividerStyle := ;
      :nRowDividerStyle := LINESTYLE_LIGHTGRAY
      :lAllowRowSizing  := .f.
      :lContrastClr     := .f.
   END

   ACTIVATE DIALOG oDlg CENTERED ;
      ON INIT ( oBrw:nRowHeight := ( oBrw:DataRect():nHeight - 2 ) / oBrw:RowCount(), ;
                oBrw:SetFocus(), .f. )

return nil
 


Image

When created with COLUMNS clause, xbrowse automatically decides picture clause, correct index tag for sorting, bonpostedit codeblock, bseek for incremental seeks, etc.

It is not necessary to specify oCol:cSortOrder, oCol:bOnPostEdit.

It is also not necessary to keep changing default alias when the browse gets focus and loses focus. It is also not necessary to restore the record number.

Not necessary:
Code: Select all  Expand view
       REQUEST ordkeyno, ordkeycount, ordkeygoto
        REQUEST DBFFPT
 
        oBrw:bGotFocus:={||dbSelectArea(cService) }
           oCol:cSortOrder         := "FIRST"
            oBrw:aCols[ 1 ]:bOnPostEdit := {|oCol, xVal, nKey| iif( nKey != VK_ESCAPE, ;
                            (oDbf:FIRST:=upper(xVal) , oDbf:save() , oBrw:refresh() ) , ) }

  oDlg:bPainted:={ ||dbSelectArea(cService) }

 
Regards

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

Re: xBrowse con Tdatabase mal en 1307

Postby rolando » Sat Oct 19, 2013 12:21 pm

Gracias por responder,

Entiendo sus comentarios. Volviendo al PRG ejemplo, agregué:

Code: Select all  Expand view
oBrw:SetRDD(.f.,.t.)


Para que permita ordenar al "clickear" sobre el head.

--------------------------------------------------------------------------------------------------------------------

Le comento dos problemas que he notado y que pueden verse en videos que adjunto.

1) Si se cierra el dialog mientras se está ejecutando un kinetic scroll, dá un error que solucioné incluyendo una función para cerrar la oDbf:

Code: Select all  Expand view
...
valid (oDbf:close() , .t.)
...
 
Function CloseoDbfxBro( oBrw, oDbf )
      oBrw:bKeyCount := {|| 0 }
      oBrw:bKeyNo := {|| 0 }
      oDbf:Close()
Return .T.


Esto funciona bien y puede verse en http://youtu.be/emTbp2nV0Ls



2) Si se cierra el dialog mientras se está en edición de un campo, da un error.

Ver en: http://youtu.be/KnbmqXg9avo

El caso (2), ¿Tiene alguna solución?. Gracias.

Rolando :D
User avatar
rolando
 
Posts: 593
Joined: Sat May 12, 2007 11:47 am
Location: San Nicolás - BA - ARGENTINA

Re: xBrowse con Tdatabase mal en 1307

Postby nageswaragunupudi » Sat Oct 19, 2013 1:32 pm

It is better not to close DBF or oDbf in the valid clause.

1) MODAL DIALOG ( in your example ) and MAIN WINDOWs
Close data after dialog exits.

ACTIVATE DIALOG .......
oDbf:Close()

2) MDICHILD

oWnd:bPostEnd := { || oDbf:Close() } // This is executed after the window is closed.

3) NON-MODAL DIALOGS AND WINDOWS (other than main window and other than mdichild windows)

Only way is to close in valid clause.
Safer is to ( oBrw:CancelEdit(), oDbf:Close() ).
Avoid using kinetic browse and be careful about btnbar and menu actions. The should check whether the dbf is open before taking action,
oBrw:bKeyCount := {|| 0 }
oBrw:bKeyNo := {|| 0 }
Make it much safer.
We get used to these over time.
Regards

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

Re: xBrowse con Tdatabase mal en 1307

Postby nageswaragunupudi » Sat Oct 19, 2013 1:38 pm

Code:
oBrw:SetRDD(.f.,.t.)[/Code]

I once again recommend using command syntax to create xbrowses. This does a a lot lot more work than simple oBrw := TXBrowse():New( oWnd ).
If you stick to the old methods, you will surely miss out many powerful features of xbrowse.
Regards

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

Re: xBrowse con Tdatabase mal en 1307

Postby rolando » Sat Oct 19, 2013 2:22 pm

Muchas gracias por todo.

Implementé:

Code: Select all  Expand view
valid (oBrw:CancelEdit(), oBrw:bKeyCount := {||0},;
             oBrw:bKeyNo := {||0}, oDbf:Close(), .t.)


Y no hay más problemas.

Además voy a tomar en cuenta su consejo y llevar todos los xBrowse's a una sintaxis actualizada.

Así funciona bien.

Code: Select all  Expand view
#include "fivewin.ch"
#include "ord.ch"
#include "xbrowse.ch"

REQUEST DBFCDX

Function main()

  Public lVeoAlias2:=.f.

    set key VK_F5 to VeoAlias()


Define window oWnd menu Buildmenu()


activate window oWnd on init HojearService()

Return nil

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

Function BuildMenu()

    local oMenu, oVerxBrowse
   
    menu oMenu 2007
        menuitem oVerxBrowse prompt 'Ver xBrowse' action HojearService() ;                    
                            message 'Probar xBrowse'
    endmenu                    


Return(oMenu)
//---------------------------------------------------------------------------------------


function HojearService()

   local oDbf, oDlg, oFont, oBrw

   oDbf  := TDataBase():Open( nil, "CUSTOMER", "DBFCDX", .t. )
   oDbf:SetOrder( "STREET" )

   DEFINE FONT oFont NAME "Arial" SIZE 6,16
   DEFINE DIALOG oDlg resource "SERVICE" FONT oFont ; // RESOURCE "DIALOG_1"
      TITLE "LISTANDO CUSTOMER " + FWVERSION

   REDEFINE XBROWSE oBrw ID 4001 DATASOURCE oDbf ;
      COLUMNS "FIRST", "LAST", "STREET" ;
      HEADERS "NOMBRE", "APELLIDO", "KALLE" ;
      PICTURES "@!", "@!", "@!" ;
      COLSIZES 130,130,160 ;
      AUTOSORT CELL LINES ;
      BACKGROUND "c:\fwh\bitmaps\backgrnd\stone.bmp"

   WITH OBJECT oBrw
      :nEditTypes       := EDIT_GET
      :nHeadStrAligns   := AL_CENTER
      :nStretchCol      := STRETCHCOL_WIDEST
      :nColDividerStyle := ;
      :nRowDividerStyle := LINESTYLE_LIGHTGRAY
      :lAllowRowSizing  := .f.
      :lContrastClr     := .f.
   END

   ACTIVATE DIALOG oDlg nowait CENTERED ;
      ON INIT ( oBrw:nRowHeight := ( oBrw:DataRect():nHeight - 2 ) / oBrw:RowCount(), ;
                oBrw:SetFocus(), .f. );
      valid (oBrw:CancelEdit(), oBrw:bKeyCount := {||0},;
             oBrw:bKeyNo := {||0}, oDbf:Close(), .t.)          

return nil
 

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

Function VeoAlias()
        // muestro en un listbox el nombre de todos los alias abiertos

    local nPaso:=1 , cPaso:=alias(nPaso) , aArray:={}

        Do while len(cPaso)>0
         aadd(aArray,{cPaso , indexord()} )
         nPaso++
         cPaso:=alias(nPaso)
        enddo
    if len(aArray) > 0
        xBrowse(aArray,"Alias en Uso")
     else
        msginfo("NO HAY NINGUN AREA ABIERTA")
    endif

 Return nil


De nuevo, Gracias.

Rolando :D
User avatar
rolando
 
Posts: 593
Joined: Sat May 12, 2007 11:47 am
Location: San Nicolás - BA - ARGENTINA

Re: xBrowse con Tdatabase mal en 1307

Postby rolando » Sun Oct 20, 2013 12:04 am

Amigo,

Hay un problema con la edición. Se puede editar pero NO SE GUARDA EN LA oDbf. Probé con el ejemplo testxbro3.prg y tampoco guarda cambios en la DBF cuando se usa la TDatabase.

Usted dice: "It is not necessary to specify oCol:cSortOrder, oCol:bOnPostEdit."

Pero sin el ":bOnPostEdit" no logro que lo editado se guarde en la DBF.

Mi amigo Alejandro Cebollido (Gracias Alejandro), estuvo viendo el problema y agregó:

Code: Select all  Expand view
:bOnPostEdits    := {|oCol, xVal, nKey| iif( nKey != VK_ESCAPE,;
                             ( nField := oDbf:FieldPos( oCol:cSortOrder ),;
                               oDbf:FieldPut( nField, xVal ),;
                               oDbf:Save(), oBrw:Refresh() ) , ) }


Con lo cual el código guarda lo editado en DBF y quedaría así:

Code: Select all  Expand view
  WITH OBJECT oBrw
 
        :nEditTypes       := EDIT_GET
            :nHeadStrAligns   := AL_CENTER
      :nStretchCol      := STRETCHCOL_WIDEST
      :nColDividerStyle := ;
      :nRowDividerStyle := LINESTYLE_LIGHTGRAY
      :lAllowRowSizing  := .f.
      :lContrastClr     := .f.
     
      :bOnPostEdits    := {|oCol, xVal, nKey| iif( nKey != VK_ESCAPE,;
                             ( nField := oDbf:FieldPos( oCol:cSortOrder ),;
                               oDbf:FieldPut( nField, xVal ),;
                               oDbf:Save(), oBrw:Refresh() ) , ) }
                             
   END


Hice un video mostrando el cambio:

http://youtu.be/idLN9dFJPiY

Saludos

Rolando :D
User avatar
rolando
 
Posts: 593
Joined: Sat May 12, 2007 11:47 am
Location: San Nicolás - BA - ARGENTINA

Re: xBrowse con Tdatabase mal en 1307

Postby nageswaragunupudi » Sun Oct 20, 2013 2:11 am

Many thanks for pointing this out and that too just intime for next release of FWH.

This is a bug. I would request you to make this correction in tdatabase class, in \fwh\source\function\database.prg

In the METHOD SetXBrowse( .... ) CLASS TDataBase, you will find this code:
Code: Select all  Expand view

   WITH OBJECT oBrw
      :oDbf          := oDbf
      :bGoTop        := {|| oBrw:oDbf:GoTop() }
      < other lines like this>
      :bSeek         := { |c| oBrw:oDbf:Seek( c, , oBrw:lSeekWild ) }
   END
 


Please insert this line after :bSeek := .... and END
Code: Select all  Expand view

  :bSaveData := { || oBrw:oDbf:Save() }
 


Revised code should look like this
Code: Select all  Expand view

   WITH OBJECT oBrw
      :oDbf          := oDbf
      :bGoTop        := {|| oBrw:oDbf:GoTop() }
      < other lines like this>
      :bSeek         := { |c| oBrw:oDbf:Seek( c, , oBrw:lSeekWild ) }
      :bSaveData     := { || oBrw:oDbf:Save() }
   END
 


With this modification everything should work correctly.
Please avoid using bOnPostEdit.

This fix is included in FWH13.09.
Regards

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

Re: xBrowse con Tdatabase mal en 1307 - Solucionado

Postby rolando » Sun Oct 20, 2013 3:36 am

Gracias por todo,

Ahora funciona correctamente.

Saludos

Rolando :D
User avatar
rolando
 
Posts: 593
Joined: Sat May 12, 2007 11:47 am
Location: San Nicolás - BA - ARGENTINA


Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 29 guests