Using oRec:Modified() in BUTTON with WHEN

Using oRec:Modified() in BUTTON with WHEN

Postby Horizon » Thu Sep 13, 2018 7:32 pm

Hi,

I have compiled "maria15.prg" with this change "WHEN oRec:Modified()" in btnbmp command.

Code: Select all  Expand view
  @ 420,020 BTNBMP PROMPT "Save"   SIZE 150,30 PIXEL FLAT OF oDlg ;                        
      ACTION ( If( oRec:Modified(), oRec:Save(), nil ), oDlg:End() ) WHEN oRec:Modified()  
 


It behaved like I expected. When I press add or edit, "Save" button is disable. When I modified any field (with enter or focus another field), "Save" button is enabled. THERE IS NO PROBLEM IN THIS CASE.

Next, I have put all the fields in a folderEx and "Save" button never Enabled when I change fields. WHY?

Thanks in advance.
Regards,

Hakan ONEMLI

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

Re: Using oRec:Modified() in BUTTON with WHEN

Postby Antonio Linares » Fri Sep 14, 2018 6:33 am

Hakan,

We are checking it
regards, saludos

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

Re: Using oRec:Modified() in BUTTON with WHEN

Postby cnavarro » Fri Sep 14, 2018 9:50 pm

Horizon wrote:Hi,

It behaved like I expected. When I press add or edit, "Save" button is disable. When I modified any field (with enter or focus another field), "Save" button is enabled. THERE IS NO PROBLEM IN THIS CASE.

Next, I have put all the fields in a folderEx and "Save" button never Enabled when I change fields. WHY?

Thanks in advance.


Please, explain better
Your put your BtnBmp in oDlg ( parent of oFolderEx ) or in oFoldeEx:aDialogs[ n ] ( for example n = 1, .... ) ?
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6541
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: Using oRec:Modified() in BUTTON with WHEN

Postby Horizon » Sat Sep 15, 2018 8:11 am

cnavarro wrote:
Horizon wrote:Hi,

It behaved like I expected. When I press add or edit, "Save" button is disable. When I modified any field (with enter or focus another field), "Save" button is enabled. THERE IS NO PROBLEM IN THIS CASE.

Next, I have put all the fields in a folderEx and "Save" button never Enabled when I change fields. WHY?

Thanks in advance.


Please, explain better
Your put your BtnBmp in oDlg ( parent of oFolderEx ) or in oFoldeEx:aDialogs[ n ] ( for example n = 1, .... ) ?


Hi Mr. Navarro,

This is modified version of Maria15.prg with folderex. This shows the problem.

Thanks.

Code: Select all  Expand view
/*
* Demonstrates oRs:EditBaseRecord( [cFieldList], [lAppend], [bEditDlg], [oBrw] )
* Where RowSet contains only some of the fields. this method can be used
* to edit full record of the table with all fields/selected fields
*
*/


#include "fivewin.ch"
#include "dbcombo.ch"

static aStates

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

function Main()

   local oCn, oRs
   local oDlg, oBrw

   FWNumFormat( "A", .t. )

   oCn   := FW_DemoDB()

   aStates  := oCn:Execute( "SELECT CODE,NAME FROM states" )
   oRs   := oCn:RowSet( "SELECT ID,FIRST,CITY,SALARY FROM customer" )

   DEFINE DIALOG oDlg SIZE 500,600 PIXEL TRUEPIXEL ;
      TITLE "EditBaseRecord()"

   @ 70,20 XBROWSE oBrw SIZE -20,-20 PIXEL OF oDlg ;
      DATASOURCE oRs AUTOCOLS ;
      COLSIZES -4, -20, -20 ;
      CELL LINES NOBORDER FOOTERS

   WITH OBJECT oBrw
      :Salary:nFooterType  := AGGR_SUM
      :MakeTotals()
      :CreateFromCode()
   END

   @ 20, 20 BTNBMP PROMPT "ADD"  SIZE 100,30 PIXEL FLAT OF oDlg ;
      ACTION oRs:EditBaseRecord( nil, .t., { |oRec| MyEditDlg( oRec ) }, oBrw )

   @ 20,130 BTNBMP PROMPT "EDIT" SIZE 100,30 PIXEL FLAT OF oDlg ;
      ACTION oRs:EditBaseRecord( nil, .f., { |oRec| MyEditDlg( oRec ) }, oBrw )

   ACTIVATE DIALOG oDlg CENTERED

return nil

static function MyEditDlg( oRec )

   local lNew     := ( oRec:RecNo == 0 )
   local oDlg, oFont, oFld

   DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-15
   DEFINE DIALOG oDlg SIZE 400,470 PIXEL  FONT oFont ;
      TITLE If( lNew, "ADD NEW ", "EDIT" ) + " RECORD"
     
    @ 2, 3 FOLDERex oFld OF oDlg SIZE 395, 390 PIXEL;
      PROMPTS "Page1", "Page2","Page3","Page4" ;
      ROUND 10
 
   @ 015,010 SAY "ID :"          SIZE 40,10 PIXEL OF oFld:aDialogs[1] RIGHT
   @ 030,010 SAY "First"         SIZE 40,10 PIXEL OF oFld:aDialogs[1] RIGHT
   @ 045,010 SAY "Last"          SIZE 40,10 PIXEL OF oFld:aDialogs[1] RIGHT
   @ 060,010 SAY "Street"        SIZE 40,10 PIXEL OF oFld:aDialogs[1] RIGHT
   @ 075,010 SAY "City"          SIZE 40,10 PIXEL OF oFld:aDialogs[1] RIGHT
   @ 090,010 SAY "State"         SIZE 40,10 PIXEL OF oFld:aDialogs[1] RIGHT
   @ 105,010 SAY "Zip"           SIZE 40,10 PIXEL OF oFld:aDialogs[1] RIGHT
   @ 120,010 SAY "HireDate"      SIZE 40,10 PIXEL OF oFld:aDialogs[1] RIGHT
   @ 135,010 SAY "Married"       SIZE 40,10 PIXEL OF oFld:aDialogs[1] RIGHT
   @ 150,010 SAY "Age"           SIZE 40,10 PIXEL OF oFld:aDialogs[1] RIGHT
   @ 165,010 SAY "Salary"        SIZE 40,10 PIXEL OF oFld:aDialogs[1] RIGHT
   @ 180,010 SAY "Notes"         SIZE 40,10 PIXEL OF oFld:aDialogs[1] RIGHT

   @ 015,055 GET oRec:ID         SIZE 050,12 PIXEL OF oFld:aDialogs[1] READONLY RIGHT
   @ 030,055 GET oRec:First      SIZE 120,12 PIXEL OF oFld:aDialogs[1] VALID !Empty( oRec:First )
   @ 045,055 GET oRec:Last       SIZE 120,12 PIXEL OF oFld:aDialogs[1] VALID !Empty( oRec:Last )
   @ 060,055 GET oRec:Street     SIZE 120,12 PIXEL OF oFld:aDialogs[1] VALID !Empty( oRec:Street )
   @ 075,055 GET oRec:City       SIZE 120,12 PIXEL OF oFld:aDialogs[1] VALID !Empty( oRec:City )
   @ 090,055 DBCOMBO oRec:State  SIZE 120,300 PIXEL OF oFld:aDialogs[1] ;
      ALIAS aStates ITEMFIELD "1" LISTFIELD "2"
   @ 105,055 GET oRec:Zip        SIZE 120,12 PIXEL OF oFld:aDialogs[1] VALID !Empty( oRec:Zip )
   @ 120,055 GET oRec:HireDate   SIZE 120,12 PIXEL OF oFld:aDialogs[1] VALID !Empty( oRec:HireDate )
   @ 135,055 CHECKBOX oRec:Married PROMPT "" SIZE 22,12 PIXEL OF oFld:aDialogs[1]
   @ 150,055 GET oRec:Age        SIZE 120,12 PIXEL OF oFld:aDialogs[1] PICTURE "99" RIGHT VALID ( oRec:Age >= 20 )
   @ 165,055 GET oRec:Salary     SIZE 120,12 PIXEL OF oFld:aDialogs[1] PICTURE "999,999.99" RIGHT VALID ( oRec:Salary > 0 )
   @ 180,055 GET oRec:Notes      SIZE 120,12 PIXEL OF oFld:aDialogs[1]

   @ 210,010 BTNBMP PROMPT "Save"   SIZE 75,15 PIXEL FLAT OF oDlg ;
      ACTION ( If( oRec:Modified(), oRec:Save(), nil ), oDlg:End() ) WHEN oRec:Modified()
     
   @ 210,120 BTNBMP PROMPT "Cancel" SIZE 75,15 PIXEL FLAT OF oDlg ACTION oDlg:End()

   ACTIVATE DIALOG oDlg CENTERED
      //ON PAINT oDlg:Box( 15, 10, 395, 390 )

return nil

 
Regards,

Hakan ONEMLI

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

Re: Using oRec:Modified() in BUTTON with WHEN

Postby cnavarro » Sat Sep 15, 2018 10:49 am

Yes, please, look my sample
You are defining the coordinates of the buttons with values that belong to dialog 1 of the folder, so the defined actions do not work, even if you have defined with the OF clause, that belong to the main dialog
I changed any size and coordinates of your sample.
I changed nClrPane of dialogs childs of folder only for control size of folder and dialogs defined
When you define the buttons in the main dialog that contains the folder and not in the dialogs of the folder, the actions that you perform in the gets of each dialog do not refresh the defined buttons in main dialog
If you define buttons of oFld:aDialogs[ 1 ], run ok also ( please look your coordinates in this case )
Therefore, you have to control the refresh of the buttons when these controls are in another dialog different from the one with the focus ( and get defined )
Look get of oRec:Last,
This can be a way to control this

Code: Select all  Expand view

/*
* Demonstrates oRs:EditBaseRecord( [cFieldList], [lAppend], [bEditDlg], [oBrw] )
* Where RowSet contains only some of the fields. this method can be used
* to edit full record of the table with all fields/selected fields
*
*/


#include "fivewin.ch"
#include "dbcombo.ch"

static aStates

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

function Main()

   local oCn, oRs
   local oDlg, oBrw

   FWNumFormat( "A", .t. )

   oCn   := FW_DemoDB()

   aStates  := oCn:Execute( "SELECT CODE,NAME FROM states" )
   oRs   := oCn:RowSet( "SELECT ID,FIRST,CITY,SALARY FROM customer" )

   DEFINE DIALOG oDlg SIZE 500,600 PIXEL TRUEPIXEL ;
      TITLE "EditBaseRecord()"

   @ 70,20 XBROWSE oBrw SIZE -20,-20 PIXEL OF oDlg ;
      DATASOURCE oRs AUTOCOLS ;
      COLSIZES -4, -20, -20 ;
      CELL LINES NOBORDER FOOTERS

   WITH OBJECT oBrw
      :Salary:nFooterType  := AGGR_SUM
      :MakeTotals()
      :CreateFromCode()
   END

   @ 20, 20 BTNBMP PROMPT "ADD"  SIZE 100,30 PIXEL FLAT OF oDlg ;
      ACTION oRs:EditBaseRecord( nil, .t., { |oRec| MyEditDlg( oRec ) }, oBrw )

   @ 20,130 BTNBMP PROMPT "EDIT" SIZE 100,30 PIXEL FLAT OF oDlg ;
      ACTION oRs:EditBaseRecord( nil, .f., { |oRec| MyEditDlg( oRec ) }, oBrw )

   ACTIVATE DIALOG oDlg CENTERED

return nil

static function MyEditDlg( oRec )

   local lNew     := ( oRec:RecNo == 0 )
   local oDlg, oFont, oFld

   DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-15
   DEFINE DIALOG oDlg SIZE 400,570 PIXEL  FONT oFont ;
      TITLE If( lNew, "ADD NEW ", "EDIT" ) + " RECORD"
     
    //@ 2, 3 FOLDERex oFld OF oDlg SIZE 395, 390 PIXEL;
    @ 2, 3 FOLDERex oFld OF oDlg SIZE 380/2, 440/2 PIXEL;
      PROMPTS "Page1", "Page2","Page3","Page4" ;
      ROUND 10
   // This for look size of folder and dialogs and not put buttons in a dialog of folder
   AEVal( oFld:aDialogs, { | o | o:SetColor( CLR_BLUE, CLR_YELLOW ) } )

   @ 015,010 SAY "ID :"          SIZE 40,10 PIXEL OF oFld:aDialogs[1] RIGHT
   @ 030,010 SAY "First"         SIZE 40,10 PIXEL OF oFld:aDialogs[1] RIGHT
   @ 045,010 SAY "Last"          SIZE 40,10 PIXEL OF oFld:aDialogs[1] RIGHT
   @ 060,010 SAY "Street"        SIZE 40,10 PIXEL OF oFld:aDialogs[1] RIGHT
   @ 075,010 SAY "City"          SIZE 40,10 PIXEL OF oFld:aDialogs[1] RIGHT
   @ 090,010 SAY "State"         SIZE 40,10 PIXEL OF oFld:aDialogs[1] RIGHT
   @ 105,010 SAY "Zip"           SIZE 40,10 PIXEL OF oFld:aDialogs[1] RIGHT
   @ 120,010 SAY "HireDate"      SIZE 40,10 PIXEL OF oFld:aDialogs[1] RIGHT
   @ 135,010 SAY "Married"       SIZE 40,10 PIXEL OF oFld:aDialogs[1] RIGHT
   @ 150,010 SAY "Age"           SIZE 40,10 PIXEL OF oFld:aDialogs[1] RIGHT
   @ 165,010 SAY "Salary"        SIZE 40,10 PIXEL OF oFld:aDialogs[1] RIGHT
   @ 180,010 SAY "Notes"         SIZE 40,10 PIXEL OF oFld:aDialogs[1] RIGHT

   @ 015,055 GET oRec:ID         SIZE 050,12 PIXEL OF oFld:aDialogs[1] READONLY RIGHT
   @ 030,055 GET oRec:First      SIZE 120,12 PIXEL OF oFld:aDialogs[1] VALID !Empty( oRec:First )
   @ 045,055 GET oRec:Last       SIZE 120,12 PIXEL OF oFld:aDialogs[1] VALID ( oDlg:AEValWhen(), !Empty( oRec:Last ) )
   @ 060,055 GET oRec:Street     SIZE 120,12 PIXEL OF oFld:aDialogs[1] VALID !Empty( oRec:Street )
   @ 075,055 GET oRec:City       SIZE 120,12 PIXEL OF oFld:aDialogs[1] VALID !Empty( oRec:City )
   @ 090,055 DBCOMBO oRec:State  SIZE 120,300 PIXEL OF oFld:aDialogs[1] ;
      ALIAS aStates ITEMFIELD "1" LISTFIELD "2"
   @ 105,055 GET oRec:Zip        SIZE 120,12 PIXEL OF oFld:aDialogs[1] VALID !Empty( oRec:Zip )
   @ 120,055 GET oRec:HireDate   SIZE 120,12 PIXEL OF oFld:aDialogs[1] VALID !Empty( oRec:HireDate )
   @ 135,055 CHECKBOX oRec:Married PROMPT "" SIZE 22,12 PIXEL OF oFld:aDialogs[1]
   @ 150,055 GET oRec:Age        SIZE 120,12 PIXEL OF oFld:aDialogs[1] PICTURE "99" RIGHT VALID ( oRec:Age >= 20 )
   @ 165,055 GET oRec:Salary     SIZE 120,12 PIXEL OF oFld:aDialogs[1] PICTURE "999,999.99" RIGHT VALID ( oRec:Salary > 0 )
   @ 180,055 GET oRec:Notes      SIZE 120,12 PIXEL OF oFld:aDialogs[1]

   @ 250,010 BTNBMP PROMPT "Save"   SIZE 75,15 PIXEL FLAT OF oDlg ;
      ACTION ( If( oRec:Modified(), oRec:Save(), nil ), oDlg:End() ) WHEN oRec:Modified()
     
   @ 250,120 BTNBMP PROMPT "Cancel" SIZE 75,15 PIXEL FLAT OF oDlg ACTION oDlg:End()

   ACTIVATE DIALOG oDlg CENTERED
      //ON PAINT oDlg:Box( 15, 10, 395, 390 )

return nil

 
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6541
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: Using oRec:Modified() in BUTTON with WHEN

Postby Horizon » Sat Sep 15, 2018 11:58 am

Thank you Mr. Navarro,

This is only sample for demontranting my problem.

1. I cannot define save, cancel buton in folder's diyalog. Because this butons are in my class. I Just define The gets.

2. I also cannot write "odlg:AEvalWhen()" every gets. There are lots of gets.

I belive it should be a short way.

Regards
Regards,

Hakan ONEMLI

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

Re: Using oRec:Modified() in BUTTON with WHEN

Postby cnavarro » Sat Sep 15, 2018 12:46 pm

And you want the status of the button to change the moment you change the value of a get, right? .......................
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6541
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: Using oRec:Modified() in BUTTON with WHEN

Postby Horizon » Sat Sep 15, 2018 12:54 pm

Yes Mr. Navarro
Regards,

Hakan ONEMLI

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

Re: Using oRec:Modified() in BUTTON with WHEN

Postby cnavarro » Sat Sep 15, 2018 2:13 pm

Or

Code: Select all  Expand view


.../...

   AEVal( oFld:aDialogs[ 1 ]:aControls, { | o | o:bLostFocus := { | o | oDlg:AEValWhen() } } )  

   @ 250,010 BTNBMP PROMPT "Save"   SIZE 75,15 PIXEL FLAT OF oDlg ;
      ACTION ( If( oRec:Modified(), oRec:Save(), nil ), oDlg:End() ) WHEN oRec:Modified()
     
   @ 250,120 BTNBMP PROMPT "Cancel" SIZE 75,15 PIXEL FLAT OF oDlg ACTION oDlg:End()

   ACTIVATE DIALOG oDlg CENTERED

 
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6541
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: Using oRec:Modified() in BUTTON with WHEN

Postby Horizon » Sat Sep 15, 2018 5:41 pm

Hi Mr. Navarro,

It seems it works when we don't use bLostFocus locally in get.

Thanks.
Regards,

Hakan ONEMLI

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

Re: Using oRec:Modified() in BUTTON with WHEN

Postby Horizon » Sun Sep 16, 2018 7:21 pm

Hi Mr. Navarro,

When I try use below line,
Code: Select all  Expand view
AEVal( oFld:aDialogs[ 1 ]:aControls, { | o | o:bLostFocus := { | o | oDlg:AEValWhen() } } )


I think there is a problem like that. When you change a field and tab or using mouse another field. There is not any change in button status. it is still disabled. but when i press tab or using mouse another field second time, button is enabled. Is it normal?

This behavior can also be seen my modified example of maria15.prg.

Thanks.
Regards,

Hakan ONEMLI

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

Re: Using oRec:Modified() in BUTTON with WHEN

Postby cnavarro » Sun Sep 16, 2018 9:39 pm

Horizon wrote:Hi Mr. Navarro,

When I try use below line,
Code: Select all  Expand view
AEVal( oFld:aDialogs[ 1 ]:aControls, { | o | o:bLostFocus := { | o | oDlg:AEValWhen() } } )


I think there is a problem like that. When you change a field and tab or using mouse another field. There is not any change in button status. it is still disabled. but when i press tab or using mouse another field second time, button is enabled. Is it normal?

This behavior can also be seen my modified example of maria15.prg.

Thanks.


Hakan, for me it's OK

Image
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6541
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: Using oRec:Modified() in BUTTON with WHEN

Postby Horizon » Mon Sep 17, 2018 7:05 am

Hi Mr. Navarro,

I think I could not tell my problem.

First, press edit button.

Change OSCAR to OSCAR1 at First field.

click Last field

You can see than Save button is not enabled.

click Street field.

Save button is enabled.

It is not ok.

You have not change any field in your example.

Thanks.
Regards,

Hakan ONEMLI

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

Re: Using oRec:Modified() in BUTTON with WHEN

Postby cnavarro » Mon Sep 17, 2018 10:39 am

Hakan, try with this

Code: Select all  Expand view

   AEVal( oFld:aDialogs[ 1 ]:aControls, { | o | if( o:ClassName() == "TGET" .and. !o:lReadOnly, ;
               ( o:bGotFocus := { | o | oDlg:AEValWhen() } ), ) } )  

 
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6541
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: Using oRec:Modified() in BUTTON with WHEN

Postby Horizon » Mon Sep 17, 2018 11:11 am

Hi Mr. Navarro,

It seems It is OK now.

Thank again.
Regards,

Hakan ONEMLI

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

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 36 guests