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

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

Postby Otto » Sat Nov 24, 2007 9:53 am

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) )
User avatar
Otto
 
Posts: 6091
Joined: Fri Oct 07, 2005 7:07 pm

Postby Antonio Linares » Sat Nov 24, 2007 12:00 pm

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
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41436
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby nageswaragunupudi » Sat Nov 24, 2007 12:26 pm

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.
Regards

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

Postby Antonio Linares » Sat Nov 24, 2007 12:29 pm

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.
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41436
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby nageswaragunupudi » Sat Nov 24, 2007 1:28 pm

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
Regards

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

Postby ShumingWang » Sun Nov 25, 2007 1:01 am

We'd changed xbrowse' nedittype from 'N' to 'B' type, so to fit dynamic lWhen clause .

Shuming Wang
ShumingWang
 
Posts: 460
Joined: Sun Oct 30, 2005 6:37 am
Location: Guangzhou(Canton),China

Postby nageswaragunupudi » Sun Nov 25, 2007 2:46 am

Mr ShumingWang

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

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

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

Postby Horizon » Thu Nov 20, 2014 7:36 am

Can you please share a latest example for it?
Regards,

Hakan ONEMLI

Harbour & MSVC 2022 & FWH 23.04
Horizon
 
Posts: 1297
Joined: Fri May 23, 2008 1:33 pm

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

Postby Silvio.Falconi » Thu Nov 20, 2014 9:20 am

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
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 6865
Joined: Thu Oct 18, 2012 7:17 pm

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

Postby nageswaragunupudi » Thu Nov 20, 2014 10:51 am

We don't need anything.
Now xbrowse works the best even on arrays too.
Regards

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

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

Postby Silvio.Falconi » Thu Nov 20, 2014 11:27 am

GOOD
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 6865
Joined: Thu Oct 18, 2012 7:17 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 49 guests