Page 1 of 1

xBrowse -array - how to add, del and select an item?

PostPosted: Sat Nov 24, 2007 9:53 am
by Otto
Hello Antonio,
Could you please post an example for:
xBrowser - ARRAY

Add, Del, Select a Item
Thanks in advance
Otto


???? does not work:
@ 300, 25 BUTTON "&Add" OF oChild PIXEL ;
ACTION ( AAdd( aStruc, Time() ), oBrw:Refresh() )

@ 300, 125 BUTTON "&SELECT" OF oChild PIXEL ;
ACTION (oBrw:Select(2) )

PostPosted: Sat Nov 24, 2007 12:00 pm
by Antonio Linares
Otto,

Here you have samples\mallorca.prg modified with your requirements. Right click on it to show a popup menu:
Code: Select all  Expand view
# INCLUDE "FiveWin.ch"
# INCLUDE "XBrowse.ch"
//-------------
FUNCTION Main()
//-------------
   LOCAL oWnd,aLin:={},i,oBrw
   FOR i:=1 TO 6
      AAdd(aLin,{i,'Descripción '+Str(i)})
   NEXT
   DEFINE WINDOW oWnd
   //--Definición Objeto TxBrowse
   oBrw:=TxBrowse():New(oWnd)
   oBrw:SetArray(aLin)
   oBrw:nColDividerStyle := LINESTYLE_BLACK
   oBrw:nRowDividerStyle := LINESTYLE_BLACK
   oBrw:nMarqueeStyle    := MARQSTYLE_HIGHLCELL

   oBrw:aCols[1]:cHeader      := 'Cod'
   oBrw:aCols[1]:cEditPicture := '@k 99'
   oBrw:aCols[1]:bClrEdit     := oBrw:bClrStd
   oBrw:aCols[1]:bOnPostEdit  := {|o,x| aLin[ oBrw:nArrayAt,1] := x }
   oBrw:aCols[1]:nEditType    := EDIT_GET
   oBrw:aCols[1]:bEditValid   := {|oGet| Valida( oGet ) } //<========
   //--
   oBrw:aCols[2]:cHeader      := 'Descripción'
   oBrw:aCols[2]:bClrEdit     := oBrw:bClrStd
   oBrw:aCols[2]:bOnPostEdit  := {|o,x| aLin[ oBrw:nArrayAt,2] := x }
   oBrw:aCols[2]:nEditType    := EDIT_GET
   //--
   oBrw:CreateFromCode()
   oBrw:bRClicked = { | nRow, nCol | ShowPopup( nRow, nCol, oBrw, aLin ) }
   oWnd:oClient:=oBrw
   
   ACTIVATE WINDOW oWnd
   
RETURN NIL
//-----------------------------------
STATIC FUNCTION Valida( oGet )
//-----------------------------------
    LOCAL lValRet:=.T.
    local bValid := oGet:bValid
    local nVal := oGet:Value()
   
    oGet:bValid = nil
   
    IF nVal>6
        // MsgAlert('No puede ser mayor que 6')
        lValRet:=.f.
    ENDIF
   
    oGet:bValid = bValid
RETURN lValRet

function ShowPopup( nRow, nCol, oBrw, aLin )

   local oMenu
   
   MENU oMenu POPUP
      MENUITEM "Add" ACTION ( AAdd( aLin, { AllTrim( Str( Len( aLin ) + 1 ) ), "New item" } ), oBrw:SetArray( aLin ), oBrw:Refresh() )
      MENUITEM "Del" ACTION ( ADel( aLin, oBrw:nArrayAt ), ASize( aLin, Len( aLin ) - 1 ), oBrw:SetArray( aLin ), oBrw:Refresh() )
      MENUITEM "Select" ACTION ( oBrw:GoTop(), oBrw:nArrayAt := 3, oBrw:Refresh() )
   ENDMENU
   
   ACTIVATE POPUP oMenu WINDOW oBrw AT nRow, nCol
   
return nil

PostPosted: Sat Nov 24, 2007 12:26 pm
by nageswaragunupudi
I would like to bring to notice some major problems with inline Edit in TxBrowse. In the above example input of a number greater than 6 is invalid and should be rejected.

Case-1
-----------
Enter 7 in the first column and pess Enter. As expected the valid clause does not accept it. Then press 'Esc' key. The edit accepts 7 and writes 7. Valid clause is not honoured.

Case-2
------------
Now press any key on any cell. Edit is invoked. If we decide not to modify the value only option as a user for us to press Esc. Now press Esc. Edit writes '0' for numeric and blank for Character fields.

Case-3
------------
In Case-2, invoke edit, enter partly and click on any other cell or click outside the window. Even an invalid value is written.

As it is, it is not safe to use the inline edit features of xbrowse in real applications.

PostPosted: Sat Nov 24, 2007 12:29 pm
by Antonio Linares
Nageswararao,

> As it is, it is not safe to use the inline edit features of xbrowse in real applications.

Yes, you are right, we need to fix those wrong behaviors.

PostPosted: Sat Nov 24, 2007 1:28 pm
by nageswaragunupudi
A few quick suggestions, though a lot more is need to be done. This is to atleast ensure that invalid and unintended values are not written to the data.

1. bPostEdit block receives three paramters. ( oCol, uValueEntered, oGet'snLastkey). Programmer should write bPostEditBlock to write changes to the database after checking the nLastKey. Safe to write data when the 3rd parameter nLastKey == VK_ENTER. In the above example the postedit block would be :
Code: Select all  Expand view
   oBrw:aCols[1]:bOnPostEdit  := {|o,x,n| if ( n == 13, aLin[ oBrw:nArrayAt,1] := x, ) }


2. While this is what the programmer has to do, this does not solve the problem, because due the way CancelEdit method is written, bPostEdit is always called with VK_RETURN as the last key even though the Get is exited by Escape or losing focus. A fix in CancelEdit method is required;
Code: Select all  Expand view
   if oCol:oEditGet != nil
//      The nexline should be commented out
//      oCol:oEditGet:nLastKey := VK_RETURN
      oCol:PostEdit()
   endif


3. Now the PostEdit block is expected to be called with the real oGet's last key. If the user exited with Escape or by losing focus of get, VK_ENTER is not expected to be the last key as seen by the PostEdit block.

Still there is a problem in some cases. User enters invalid value and presses Enterkey. Valid Block does not allow the input. User wants to give up and clicks on another cell so that get loses its focus. Then also PostEdit block is called and in this case the last key is VK_ENTER. When Get is created get's bLostFocus is set to {||::PostEdit()}. So when the get loses focus it calls PostEdit method without parameters. This call to postedit does not go through CancelEdit method.
A suggested fix is :
Code: Select all  Expand view
while initializing the Get:
::oEditGet:bLostFous := {|| PostEdit(nil,nil, VK_ESCAPE)}  // can be any value to indicate loss of focus.

PostEdit method:
method postedit( xValue, lButton, nLastKey )

...
..
..
   case ::nEditType == EDIT_GET
      If ::oEditGet != nil
       // insert the following 3 lines
         if nLastKey != nil
            ::oEditGet:nLastKey := nLastKey
        endif


With these changes I could prevent writing of invalid data. By abundant caution I am once again checking bValidBlock within PostEdit block, which will not be necessary once the edit behaviour is fully rectified.

Still I have a problem and not able to find a solution. Enter an invalid value and press enter. Later with escape key or losing focus, exit edit ( atleast user thinks he exited the edit ). But I find that the GetObject is still there. When we navigate back to that cell, Get is shown again. Yet to find what to do for this.

This discussion is limited to single line edit in case of nEditType = 1 only. I have not mentioned the problems with edittypes 2 and above.

Hope we can get xBrowse with inline edit that can be used in real applications with 7.12

PostPosted: Sun Nov 25, 2007 1:01 am
by ShumingWang
We'd changed xbrowse' nedittype from 'N' to 'B' type, so to fit dynamic lWhen clause .

Shuming Wang

PostPosted: Sun Nov 25, 2007 2:46 am
by nageswaragunupudi
Mr ShumingWang

Have you modified xbrowse's Edit method to make it reliable? If so can you share your logic please?

Re: xBrowse -array - how to add, del and select an item?

PostPosted: Thu Nov 20, 2014 7:36 am
by Horizon
Can you please share a latest example for it?

Re: xBrowse -array - how to add, del and select an item?

PostPosted: Thu Nov 20, 2014 9:20 am
by Silvio.Falconi
Otto,
Thanks to Rao I made a small class to Filter on Xbrowse , working from the Xbrarray.prg
I hope you need it to Kown how add ,del , an item on array

Re: xBrowse -array - how to add, del and select an item?

PostPosted: Thu Nov 20, 2014 10:51 am
by nageswaragunupudi
We don't need anything.
Now xbrowse works the best even on arrays too.

Re: xBrowse -array - how to add, del and select an item?

PostPosted: Thu Nov 20, 2014 11:27 am
by Silvio.Falconi
GOOD