FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour xBrowse -array - how to add, del and select an item?
Posts: 6984
Joined: Fri Oct 07, 2005 07:07 PM

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

Posted: Sat Nov 24, 2007 09: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) )

Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM

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

Posted: 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:
# 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
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM

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

Posted: 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
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM

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

Posted: 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
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM

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

Posted: Sat Nov 24, 2007 01: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 :
   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;
   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 :
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
Posts: 474
Joined: Sun Oct 30, 2005 06:37 AM

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

Posted: Sun Nov 25, 2007 01:01 AM

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

Shuming Wang

http://www.xtech2.top
Mobile:(86)13802729058
Email:100200651@qq.com
QQ:100200651
Weixin: qq100200651
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM

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

Posted: Sun Nov 25, 2007 02: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
Posts: 1387
Joined: Fri May 23, 2008 01:33 PM

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

Posted: Thu Nov 20, 2014 07:36 AM

Can you please share a latest example for it?

Regards,



Hakan ONEMLI



Harbour & MSVC 2022 & FWH 23.06
Posts: 7318
Joined: Thu Oct 18, 2012 07:17 PM

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

Posted: Thu Nov 20, 2014 09: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 March-April 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
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM

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

Posted: 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
Posts: 7318
Joined: Thu Oct 18, 2012 07:17 PM

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

Posted: Thu Nov 20, 2014 11:27 AM

GOOD

Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 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

Continue the discussion