very strange behavior in xBrowse (Bug?)

very strange behavior in xBrowse (Bug?)

Postby FranciscoA » Tue Aug 30, 2011 1:09 am

Dears all.
By chance, I noticed a very strange behavior in xBrowse (ver. 10.06). Let me explain:

In MDI environment, I have a window oChild (of oWnd) containing a xBrowse to edit data.
This browser is conditioned to come to the end and beyond it (bPastEof), add a blank record ready for editing. If you do not enter any value and press enter, this state is evaluated and displays a dialog to choose the necessary data. (imagine that this dialog contains the catalog of products).

Well, if you use the directional keys on the items exceed xBrowse, everything works fine.
But ... if you use the arrow below the vertical scroll by surpassing add a blank record, and if it takes another click on the arrow and keep the mouse cursor over it, it triggers an event so overwhelming, opening the dialog, and this action does not stop until the mouse is placed on dialog, having to close each of them to continue. If this is not done immediately, it can consume all the resources of the cpu, and we know the results when this happens.

I coded a small example show here, in order to test the above. Use Clientes.dbf file found in the Samples folder.

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

static oWnd

//----------------
Function Main()
   SET DELETED ON
   DEFINE WINDOW oWnd MDI TITLE "PRUEBA DE XBROWSE"
   ACTIVATE WINDOW oWnd MAXIMIZED ;
       ON INIT Prueba()
return nil

//----------------------------//
Function Prueba()
local oChild, oBrw, oCol
local cAlias
local oBotSave,oBotCanc

DbUseArea(.t.,,"Clientes","Clientes",.F.)
cAlias:=Alias()

  DEFINE WINDOW oChild MDICHILD OF oWnd TITLE "PRUEBA XBROWSE"

  @34,700 BTNBMP oBotSave LEFT 2007 PROMPT "Guardar" SIZE 100,28 OF oChild ACTION  msgInfo("Hola")
  @oBotSave:nBottom+8,700 BTNBMP oBotCanc LEFT 2007 PROMPT "Cancelar" SIZE 100,28 OF oChild ACTION oWnd:End()


   oBrw := TXBrowse():New( oChild )
   oBrw:cAlias := cAlias

   oBrw:nMarqueeStyle    := MARQSTYLE_HIGHLCELL
   oBrw:nColDividerStyle     := LINESTYLE_INSET
   oBrw:nRowDividerStyle     := LINESTYLE_INSET
   oBrw:lColDividerComplete  := .t.
   oBrw:lFooter              := .t.
   oBrw:lRecordSelector      := .t.

   oBrw:lFastEdit := .t.

   oBrw:bPastEof = {|| if( lCCtaOK(oBrw), (Dbappend(), oBrw:GoLeftMost(), oBrw:Refresh(), oBrw:aCols[ 1 ]:Edit() ),) }

   oCol = oBrw:AddCol()
   oCol:bEditValue = { || (cAlias)->telefono }
   oCol:cHeader := "TELEFONO"
   oCol:nEditType = EDIT_GET
   oCol:nWidth = 140
   oCol:bGetChange = {| k, f, o, oCol | If( Len( RTrim( o:oGet:Buffer ) ) == Len( o:oGet:Buffer ),;   //Daniel
                                           ( o:SendMsg( WM_KEYDOWN, VK_RETURN ) ), ) }                //Daniel
   oCol:bOnPostEdit = { | oCol, xVal, nKey | If( RecCount() == 0, ( DbAppend(), oBrw:Refresh() ),) ,;
                        If( nKey == VK_RETURN, ((cAlias)->telefono := xVal,if(lCCtaOK(oBrw),oBrw:nColSel:=1,)) , ) ,;
                        If( nKey == VK_ESCAPE .and. Empty((cAlias)->telefono), ( (cAlias)->(dbDelete()),(cAlias)->(__dbPack()),(cAlias)->(dbGoBottom()),oBrw:Refresh() ), ) }

   oCol = oBrw:AddCol()
   oCol:bEditValue = { || (cAlias)->nombre }
   oCol:cHeader := "NOMBRE"
   oCol:nEditType = EDIT_GET
   oCol:nWidth = 230
   oCol:bGetChange = {| k, f, o, oCol | If( Len( RTrim( o:oGet:Buffer ) ) == Len( o:oGet:Buffer ),;    //Daniel
                                           ( o:SendMsg( WM_KEYDOWN, VK_RETURN ) ), ) }                 //Daniel
   oCol:bOnPostEdit = { | oCol, xVal, nKey | If( RecCount() == 0, ( DbAppend(), oBrw:Refresh() ),) ,;
                        If( nKey == VK_RETURN, ((cAlias)->nombre := xVal,if(lCCtaOK(oBrw),oBrw:nColSel:=1,)), ) }

   oBrw:SetRDD()
   oBrw:CreateFromCode()

   oBrw:bKeyDown :={ | nKey | if(nKey == VK_DELETE, ( (oBrw:cAlias)->(dbdelete()), (oBrw:cAlias)->(dbpack()), oBrw:Refresh() ),) }

   oChild:bGotFocus = { || dbselectarea( cAlias ) }  

   ACTIVATE WINDOW oChild MAXIMIZED;
      ON INIT (  oBrw:nHeight := oChild:nHeight-163, oBrw:nWidth := oChild:nWidth-12, oBrw:nTop:=130 ) ;
         VALID ( oBrw:CancelEdit(),(cAlias)->(dbCloseArea()), .T. )

   RETURN NIL

//----------------//
Function lCCtaOK(oBrw)
local oDlg
local cCodigo:=(oBrw:cAlias)->telefono

if empty(cCodigo)
   DEFINE DIALOG oDlg FROM 1,1 TO 30,60
   ACTIVATE DIALOG oDlg CENTERED
   return .f.
endif

Return .t.

 


Can you help me?
Sorry for my English.

Regards.

Francisco.
Francisco J. Alegría P.
Chinandega, Nicaragua.

Fwxh-MySql-TMySql
User avatar
FranciscoA
 
Posts: 2112
Joined: Fri Jul 18, 2008 1:24 am
Location: Chinandega, Nicaragua, C.A.

Re: very strange behavior in xBrowse (Bug?)

Postby nageswaragunupudi » Tue Aug 30, 2011 9:12 am

Not a bug with XBrowse.

Using bPastEof is a bit tricky. We need to ensure that (1) repeated append is prevented as long as there is an unfinished append and (2) when the cursor row moves away from the appending row while the append is unfinished, the append should be cancelled properly.

Extreme care should be taken for bOnPostEdit. It is highly desirable not to code this block inside the application program and leave it to xbrowse to automatically generate this codeblock, which is well tested and bugfree. It is highly recommended to use commend syntax using columns clause or if SetRdd() is used, create the columns with the columns parameter of the setrdd method. This way we avoid many possibilties of introducing bugs and facing enexpected behavior.

I am giving here a test program. This can be compiled and tested. This is my approach to achieve similar results like the above sample.
Please try and see if you find any problems with the sample I posted below. The same logic can be adopted.
Code: Select all  Expand view
#include "fivewin.ch"
#include "xbrowse.ch"

REQUEST DBFCDX

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

function Main()

   local oWnd, oBar, oFont

   RDDSetDefault( "DBFCDX" )
   SET DELETED ON

   if ! File( 'TestTrn.Dbf' )
      CreateTestDbf()
   endif

   DEFINE FONT oFont NAME 'TAHOMA' SIZE 0,-12
   DEFINE WINDOW oWnd MDI
   oWnd:SetFont( oFont )

   DEFINE BUTTONBAR oBar OF oWnd SIZE 100,32 2007
   SET MESSAGE OF oWnd TO '' 2007

   DEFINE BUTTON OF oBar PROMPT "XBrowse" ACTION XbrAppend( This )
   DEFINE BUTTON OF oBar PROMPT "Quit" ACTION oWnd:End()

   ACTIVATE WINDOW oWnd
   RELEASE FONT oFont

return 0

static function XbrAppend( oBtn )

   local oWnd, oBrw

   oBtn:Disable()

   USE TESTTRN NEW ALIAS TRN EXCLUSIVE

   DEFINE WINDOW oWnd MDICHILD OF WndMain()

   @ 0,0 XBROWSE oBrw OF oWnd ;
      COLUMNS 'Code', 'Item', 'Rate', 'Quantity' ;
      ALIAS 'TRN' CELL LINES FASTEDIT

   oBrw:Amount    := { || oBrw:Rate:Value * oBrw:Quantity:Value }

   WITH OBJECT oBrw
      :Cargo            := 0 // While appending assign the new record to cargo
      WITH OBJECT :Code
         :nEditType     := EDIT_BUTTON
         :bEditBlock    := { || SelectItem( oBrw ) }
      END

      :Quantity:nEditType  := EDIT_GET
      :bPastEof         := { || (oBrw:cAlias)->( AppendRec( oBrw ) ) }
      :bChange          := { || (oBrw:cAlias)->( CheckAppend( oBrw ) ) }
   END

   oBrw:CreateFromCode()
   oWnd:oClient   := oBrw

   oWnd:bPostEnd := { || TRN->( DbCloseArea() ), oBtn:Enable() }

   ACTIVATE WINDOW oWnd ON INIT oBrw:SetFocus() ;
      VALID CheckAppend( oBrw, .t. )

return nil

static function AppendRec( oBrw )

   if oBrw:Cargo == 0  // not in append mode
      APPEND BLANK
      GO BOTTOM
      oBrw:Cargo  := RecNo()
      oBrw:Refresh()
      oBrw:GoLeftMost()
      oBrw:Code:Edit()
   endif

return nil

static function CheckAppend( oBrw, lExit )

   local nRecNo   := RecNo()

   DEFAULT lExit  := .f.

   if oBrw:Cargo > 0 .and. ( lExit .or. oBrw:Cargo != nRecNo )
      // there is an unfinished append
      // cancel it
      GOTO oBrw:Cargo
      DELETE
      oBrw:Cargo  := 0
      if ! lExit
         GOTO nRecNo
         oBrw:Refresh()
      endif
   endif
   if lExit
      PACK
   endif

return .t.

static function SelectItem( oBrw1 )

   local aItems := { { 1, "Item.1", 20 }, { 2, "Item.2", 30 }, { 3, "Item.3", 40 } }
   local nRet     := oBrw1:Code:Value

   XBROWSER aItems ;
      SETUP ( oBrw:cHeaders := { "Code", "Item", "Rate" } ) ;
      SELECT ( nRet := oBrw:aRow[ 1 ], ;
               oBrw1:Item:Value := oBrw:aRow[ 2 ], ;
               oBrw1:Rate:Value := oBrw:aRow[ 3 ], ;
               oBrw1:Cargo  := 0, ;
               oBrw1:nColSel := 4, ;
               oBrw1:Refresh() )

return nRet

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

static function CreateTestDbf()

   local aCols    := { ;
      { "CODE",      "N",  4, 0  }, ;
      { "ITEM",      "C", 20, 0  }, ;
      { "RATE",      "N",  6, 2  }, ;
      { "QUANTITY",  "N",  4, 0  }  }

   DBCREATE( "TESTTRN", aCols )

   USE TESTTRN EXCLUSIVE
   APPEND BLANK
   FIELD->CODE       := 1
   FIELD->ITEM       := "Item.1"
   FIELD->RATE       := 20
   FIELD->QUANTITY   := 3
   CLOSE TESTTRN

return nil

//----------------------------------------------------------------------------//
 
Regards

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

Re: very strange behavior in xBrowse (Bug?)

Postby FranciscoA » Tue Aug 30, 2011 2:36 pm

Thanks, Rao. Your example works fine, but the current get field keeps flashing. It is consuming resources?

I need to make many evaluations before recording the corresponding item, so use bPastEof and bOnPostEdit.
I'll try to adapt your code to mine.

Thanks, again.

Regards.
Francisco J. Alegría P.
Chinandega, Nicaragua.

Fwxh-MySql-TMySql
User avatar
FranciscoA
 
Posts: 2112
Joined: Fri Jul 18, 2008 1:24 am
Location: Chinandega, Nicaragua, C.A.

Re: very strange behavior in xBrowse (Bug?)

Postby nageswaragunupudi » Tue Aug 30, 2011 3:31 pm

For this purpose I installed 10.6 and worked out this sample and is working well. If you still have specific problems please let us know. Whatever that is possible with 10.6, we shall try to help.
Regards

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

Re: very strange behavior in xBrowse (Bug?)

Postby FranciscoA » Tue Aug 30, 2011 5:20 pm

Rao, for the moment I've solved it by omitting the vertical scroll bar. I will try to fix it via code.

regards
Francisco J. Alegría P.
Chinandega, Nicaragua.

Fwxh-MySql-TMySql
User avatar
FranciscoA
 
Posts: 2112
Joined: Fri Jul 18, 2008 1:24 am
Location: Chinandega, Nicaragua, C.A.


Return to FiveWin for Harbour/xHarbour

Who is online

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