Page 1 of 1

GET and bLostFocus

PostPosted: Wed Jul 12, 2023 1:20 pm
by Maurizio
Hello,
I have a problem with GET dialog and XBROWSE (as example)

When I leave the field First , I'd like the data in the browse udated .
This works if I switch from First to Last
But when I switch from First to browse the update is on the wrong row because the pointer has already changed.

Regards Maurizio
www.nipeservice.com

Code: Select all  Expand view
#include "FiveWin.Ch"
 
REQUEST DBFCDX
//----------------------------------------------------------------------------//
function main()
   local  aData, oDlg, oBrw,  cFirst := '',cLast :='' ,oGet,oGet1

   USE CUSTOMER NEW VIA "DBFCDX"
   aData       := FW_DbfToArray("FIRST, LAST")
   CLOSE DATA

   cFirst := aData[1,1]
   cLast  := aData[1,2]
 
   DEFINE DIALOG oDlg SIZE 800,400 PIXEL  

   @ 10,10  SAY 'Firs'   OF oDlg update PIXEL
   @ 10,60  get oGet Var cFirst   OF oDlg update PIXEL  SIZE 100,15

    oGet:bLostFocus :=<|o|
            Local n :=  oBrw:nArrayAt
            Local uOldVal := oGet:cText
            aData[n,1] := uOldVal
            oBrw:RefreshCurrent()
        Return nil  
    >
       
   
   @ 10,200  SAY 'Last'   OF oDlg update PIXEL
   @ 10,260 get oGet1 Var cLast   OF oDlg update PIXEL  SIZE 100,15
   
   @ 30,10 XBROWSE oBrw SIZE -10,-10 PIXEL OF oDlg DATASOURCE aData AUTOCOLS ;
       HEADERS "FIRST", "LAST" CELL LINES NOBORDER

   WITH OBJECT oBrw
      :CreateFromCode()
      :bChange := <||
            cFirst := aData[oBrw:nArrayAt,1]
            cLast  := aData[oBrw:nArrayAt,2]
            oDlg:Update()
           Return nil
        >
   END
 
   ACTIVATE DIALOG oDlg CENTERED
 
return nil

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

Re: GET and bLostFocus

PostPosted: Wed Jul 12, 2023 1:28 pm
by Marc Venken

Re: GET and bLostFocus

PostPosted: Wed Jul 12, 2023 1:54 pm
by Marc Venken
I tried this and seems to work

@ 10,60 get oGet Var cFirst OF oDlg update PIXEL SIZE 100,15;
valid( (oBrw:first:varput(cFirst),.t.,oBrw:refresh()),.t.)

oGet:bLostFocus :=<|o| end rest is not needed.
....

Re: GET and bLostFocus

PostPosted: Wed Jul 12, 2023 1:59 pm
by Maurizio
Thanks Marc
but it does not work :(
Maurizo

Re: GET and bLostFocus

PostPosted: Wed Jul 12, 2023 2:03 pm
by Marc Venken
Code: Select all  Expand view

#include "FiveWin.Ch"

REQUEST DBFCDX
//----------------------------------------------------------------------------//
function main()
   local  aData, oDlg, oBrw,  cFirst := '',cLast :='' ,oGet,oGet1

   USE CUSTOMER NEW VIA "DBFCDX"
   aData       := FW_DbfToArray("FIRST, LAST")
   CLOSE DATA

   cFirst := aData[1,1]
   cLast  := aData[1,2]

   DEFINE DIALOG oDlg SIZE 800,400 PIXEL

   @ 10,10  SAY 'Firs'   OF oDlg update PIXEL
   @ 10,60  get oGet Var cFirst   OF oDlg update PIXEL  SIZE 100,15;
     valid( (oBrw:first:varput(cFirst),.t.,oBrw:refresh()),.t.)

   @ 10,200  SAY 'Last'   OF oDlg update PIXEL
   @ 10,260 get oGet1 Var cLast   OF oDlg update PIXEL  SIZE 100,15

   @ 30,10 XBROWSE oBrw SIZE -10,-10 PIXEL OF oDlg DATASOURCE aData AUTOCOLS ;
       HEADERS "FIRST", "LAST" CELL LINES NOBORDER

   WITH OBJECT oBrw
      :CreateFromCode()
      :bChange := <||
            cFirst := aData[oBrw:nArrayAt,1]
            cLast  := aData[oBrw:nArrayAt,2]
            oDlg:Update()
           Return nil
        >
   END

   ACTIVATE DIALOG oDlg CENTERED

return nil

 

Re: GET and bLostFocus

PostPosted: Wed Jul 12, 2023 2:05 pm
by Marc Venken
indeed. Not working what you ask. Sorry

Re: GET and bLostFocus

PostPosted: Thu Jul 13, 2023 5:24 am
by Antonio Linares
Dear Maurizio,

You example works fine here

> But when I switch from First to browse the update is on the wrong row because the pointer has already changed

Are you using an INDEX ? Here the xbrowse pointer does not change

Re: GET and bLostFocus

PostPosted: Thu Jul 13, 2023 3:24 pm
by Maurizio
Hello, I think I explained it wrong.
If I change the focus from the FIRST field to the LAST field, the data is changed because oBrw:nArrayAt is still correct.

On the other hand, if I change the focus by clicking on another row in xbrowse (not the one i am reading in FIRST/LAST),+
the data is not changed because I lost the correct row, oBrw:nArrayAt already has the value of the new row.

Can I find a solution to this problem?

Re: GET and bLostFocus

PostPosted: Thu Jul 13, 2023 4:51 pm
by karinha
Maurizio, lo siento, pero no veo dónde está el "error", en mi opinión, está funcionando perfectamente. ¿Qué en tu opinión no es correcto?

Maurizio, sorry, but I can't see where the "error" is, in my opinion, it's working perfectly. What in your opinion is not correct?

Code: Select all  Expand view

#include "FiveWin.Ch"
 
REQUEST OrdKeyNo, OrdKeyCount, OrdCreate, OrdKeyGoto
REQUEST DBFCDX, DBFFPT

FUNCTION Main()

   LOCAL aData, oDlg, oBrw,  cFirst := '', cLast :=' ' , oGet, oGet1, oFont

   USE CUSTOMER NEW EXCLUSIVE
   GO TOP

   INDEX ON Field->First TO CUSTOMER ASCEND
   // INDEX ON Field->Last  TO CUSTOMER

   CLOSE DATA

   USE CUSTOMER INDEX CUSTOMER SHARED NEW
   GO TOP

   aData  := FW_DbfToArray( "FIRST, LAST" )

   cFirst := aData[1,1]
   cLast  := aData[1,2]
 
   DEFINE FONT oFont  NAME "Ms Sans Serif"  SIZE 00, -14 BOLD

   DEFINE DIALOG oDlg SIZE 800, 400 PIXEL FONT oFont

   oDlg:lHelpIcon := .F.

   @ 10,10 SAY 'Firs' OF oDlg update PIXEL

   @ 10,60 get oGet Var cFirst OF oDlg update PIXEL  SIZE 100,15

   oGet:bLostFocus :=<|o|
      Local n :=  oBrw:nArrayAt
      Local uOldVal := oGet:cText
      aData[n,1] := uOldVal
      oBrw:RefreshCurrent()
      Return nil
   >
   
   @ 10,200  SAY 'Last' OF oDlg update PIXEL

   @ 10,260 get oGet1 Var cLast OF oDlg update PIXEL SIZE 100,15
   
   @ 30,10 XBROWSE oBrw SIZE -10,-10 PIXEL OF oDlg DATASOURCE aData AUTOCOLS ;
       HEADERS "FIRST", "LAST" CELL LINES NOBORDER

   WITH OBJECT oBrw

      oBrw:lIncrFilter := .T.
      oBrw:lSeekWild   := .T.

      :CreateFromCode()
      :bChange := <||
      cFirst := aData[oBrw:nArrayAt,1]
      cLast  := aData[oBrw:nArrayAt,2]
      oDlg:Update()
      Return nil
      >

   END

   ACTIVATE DIALOG oDlg CENTERED ;
      ON INIT ( oBrw:cSeek( "" ), oBrw:SetFocus(), .F. )

   CLOSE DATA

   oFont:End()
 
RETURN NIL

// FIN / END
 


Regards, saludos.

Re: GET and bLostFocus

PostPosted: Thu Jul 13, 2023 8:07 pm
by Marc Venken
If we enter a name in the get and not use any key, but simply point the mouse to a row on xbrowse, the input from the get is not validated or even known, so the change is doing it with the original data in the get.

Aslong we don't enter the get the the get is keeping the original data. I see the problem : the newdata in the get is not yet confirmed. so can't be saved. I do think there is a data in Get that can be used, but did not found it

Re: GET and bLostFocus

PostPosted: Fri Jul 14, 2023 4:15 am
by Maurizio
Antonio,
it's not a problem of INDEX because in xbrowse I use array.

I think the problem is when we point the mouse to another row
of xbrowse:
1-xbrowse changes row
2-get executes lostfocus
Antonio try this:
Example 1This works
1-xbrowse on line 1
2-make a change of First
3-steps to the Last field
at the same time the value of First in row 1( in xbrowse ) is updated
Example 2 this doesn't work
1-xbrowse on row 1
2-make a change of First
3-click in xbrowse row 3
in this case line 1 is not updated