Dtepicker and VALID clausule

Dtepicker and VALID clausule

Postby Franklin Demont » Tue Nov 12, 2013 9:07 am

Hello,

Next program uses the valid clausule from a get or dtepicker. When the valid is not satisfied , a message error is displayed and the original value is restored.

This doesn't work when :

1) The second get has focus
2) clicking the 'action' key from the date picker to pick a date in 2014
3) TAB to have the next control

A wrong date is accepted while the valid clausule is not executed.
With Shift-Tab the valid clausule is executed.

Also when we give focus too the (wrong) date , TAB can be used to activate the valid clausule

Very strange !!!!!!

FWH1303 , BCC582 , Harbour

Frank




Code: Select all  Expand view

// Testing GETs

#include "FiveWin.ch"
#include "DtPicker.ch"

function Main()
   LOCAL oDlg, oGet[3]
   LOCAL cCad := "Testing    "
   LOCAL nNum := 0
   LOCAL dDat := Date()

   Set century On
   Set Date French

   SET _3DLOOK ON

   DEFINE DIALOG oDlg TITLE "TGet from " + FWDESCRIPTION
   //DEFINE WINDOW oDlg TITLE "TGet from " + FWDESCRIPTION
   @ 1,    2 SAY "Text..:" OF oDlg
   @ 1,    6 GET oGet[1] VAR cCad OF oDlg SIZE 60, 10 PICTURE "@K" VALID MyValid(oGet[1],'oGet:Varget()="T"')
   oGet[1]:lClrFocus := .T.
   @ 1.8,  2 SAY "Number:" OF oDlg
   @ 2,    6 GET oGet[2] VAR nNum OF oDlg SIZE 60, 10 PICTURE "9999999.99"
   @ 2.6,  2 SAY "Date:" OF oDlg
   //@ 3,    6 GET oGet[3] VAR dDat PICTURE "@E" OF oDlg SIZE 60, 10 VALID MyValid(oGet[3],'YEAR(oGet:Varget())=2013')
   //@ 3,    6 DTPICKER oGet[3] VAR dDat OF oDlg SIZE 60, 10 VALID MyValid(oGet[3],'YEAR(oGet:Varget())=2013')
   @ 40,   48 DTPICKER oGet[3] VAR dDat OF oDlg SIZE 60, 10 VALID MyValid(oGet[3],'YEAR(oGet:Varget())=2013') PIXEL
              oGet[3]:cCaption := DTOC(dDat)  
   @ 3,    7 BUTTON "&Ok" OF oDlg SIZE 30, 12 ACTION oDlg:End() WHEN CheckValid(oDlg)
   @ 3,   16 BUTTON "&Cancel" SIZE 30, 12 OF oDlg ACTION oDlg:End() CANCEL
   ACTIVATE DIALOG oDlg CENTERED ;
      VALID IIF(GetKeyState(27),DlgEsc(oDlg),.T.)

return nil

*********************************************************************************************
FUNCTION MyValid(oGet,cCond,cText,lRestore,lShow)
*************************************************
LOCAL bCond
LOCAL lOk := .T.
LOCAL Original := oGet:cCaption , c
DEFAULT lRestore := .T. , lShow := .T.
IF ! ValType(cCond)$"BC"
   ? "Error in Valid clausule" , ProcName(1) , ProcName(2)
   RETURN .T.
END
IF ValType(cCond) == "C"
   DEFAULT cText := ALLTRIM(cValToChar(oGet:Varget())) + " doesn't match " + cCond + " !"
   bCond := &("{|oGet|" + cCond + "}")
ELSE
   cText := cValToChar(oGet:Varget()) + " : not accepted"
END
lOk := EVAL(bCond,oGet)
IF CheckProcList("CHECKVALID")
   RETURN lOk
END

IF ! lOk
   IF lShow
      MsgAlert(cText,"Ongeldige invoer")
   End
   IF lRestore
      IF oGet:ClassName == "TDATEPICK"
         Original := CTOD(Original)
      END
      oGet:Varput(Original)
      oGet:Refresh()
   END
ELSE
   IF oGet:ClassName == "TDATEPICK"
      c := DTOC(oGet:Varget())
   ELSE
      c := oGet:Varget()
   END      
   oGet:cCaption := c    
END
RETURN lOk
******************************************************************************************

FUNCTION CheckValid(Self)
************************
LOCAL Obj
FOR EACH Obj IN ::aControls
    IF __ObjHasData(Self,"bValid")
       IF Obj:bValid <> nil .AND. VALTYPE(Obj:bValid) == "B"
          IF ! EVAL(Obj:bValid)  
             RETURN .F.
          END        
       END
    END
NEXT
RETURN .T.
******************************************************************************************
FUNC CheckProcList(cProc)
*************************
LOCAL ok := .F. , i := 0 , hlp
DO WHIL ! ok .AND. ! EMPTY(hlp := PROCNAME(i++))
 ok := (UPPER(cproc) IN hlp)
END
RETU ok
*****************************************************************************************
FUNC DlgEsc(Self)
*****************
LOCAL Obj , oGet
LOCAL Original
FOR EACH Obj IN ::aControls
    IF Obj:lFocused
       oGet := Obj
       EXIT
    END
NEXT
IF oGet <> nil
   Original := oGet:cCaption
   IF oGet:ClassName="TDATEPICK"
      Original := CTOD(Original)
   END
   IF Original == oGet:Varget()
      FOR EACH Obj IN ::aControls
          IF __ObjHasData(Obj,"lCancel") .AND. Obj:lCancel
             xSetfocus(Obj)
             EXIT
          END
      NEXT
      RETURN .F.
   END
   oGet:Varput(Original)
   oGet:Refresh()
END
RETURN .F.
*****************************************************************************************
function xSetFocus( oObx )
**************************
// function from local.fivewin.english 4/1/2003 Kleyber Derick
local oTempo:=""
local lGet := oObx:ClassName $ "TGET TMULTIGET"
define timer oTempo interval 10 of oObx:oWnd ;
  action (oObx:SetFocus(), IIF(lGet , oObx:SetPos(0) , ), oTempo:Deactivate() )
activate timer oTempo

return nil

 
test
Franklin Demont
 
Posts: 166
Joined: Wed Aug 29, 2012 8:25 am

Re: Dtepicker and VALID clausule

Postby Antonio Linares » Tue Nov 12, 2013 10:58 am

Frank,

I have modified this line of your code:

@ 40, 48 DTPICKER oGet[3] VAR dDat OF oDlg SIZE 60, 10 VALID ( MsgBeep(), .T. ) /* MyValid(oGet[3],'YEAR(oGet:Varget())=2013') */ PIXEL

and the beep seems to be fine. Could you please test it and check how to reproduce the problems that you describe ? thanks
regards, saludos

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

Re: Dtepicker and VALID clausule

Postby Franklin Demont » Tue Nov 12, 2013 12:49 pm

Antonio Linares wrote:Frank,

I have modified this line of your code:

@ 40, 48 DTPICKER oGet[3] VAR dDat OF oDlg SIZE 60, 10 VALID ( MsgBeep(), .T. ) /* MyValid(oGet[3],'YEAR(oGet:Varget())=2013') */ PIXEL

and the beep seems to be fine. Could you please test it and check how to reproduce the problems that you describe ? thanks


Antonio ,

The problems seems to come from the when clausule in :

@ 3, 7 BUTTON "&Ok" OF oDlg SIZE 30, 12 ACTION oDlg:End() WHEN CheckValid(oDlg)

Omitting the when clausule solves the problem.

Code: Select all  Expand view

FUNCTION CheckValid(Self)
************************
LOCAL Obj
FOR EACH Obj IN ::aControls
    IF __ObjHasData(Self,"bValid")
       IF Obj:bValid <> nil .AND. VALTYPE(Obj:bValid) == "B"
          IF ! EVAL(Obj:bValid)  
             RETURN .F.
          END        
       END
    END
NEXT
RETURN .T.
 


When you heer a beep , it comes from here

Frank
test
Franklin Demont
 
Posts: 166
Joined: Wed Aug 29, 2012 8:25 am

Re: Dtepicker and VALID clausule

Postby Franklin Demont » Tue Nov 12, 2013 1:17 pm

Antonio ,

Code: Select all  Expand view

// Testing GETs
#include "FiveWin.ch"
#include "DtPicker.ch"

function Main()
   LOCAL oDlg, oGet[3]
   LOCAL cCad := "Testing    "
   LOCAL nNum := 0
   LOCAL dDat := Date()

   Set century On
   Set Date French

   SET _3DLOOK ON

   DEFINE DIALOG oDlg TITLE "TGet from " + FWDESCRIPTION
   @ 1,    2 SAY "Text..:" OF oDlg
   @ 1,    6 GET oGet[1] VAR cCad OF oDlg SIZE 60, 10
   oGet[1]:lClrFocus := .T.
   @ 1.8,  2 SAY "Number:" OF oDlg
   @ 2,    6 GET oGet[2] VAR nNum OF oDlg SIZE 60, 10 PICTURE "9999999.99"
   @ 2.6,  2 SAY "Date:" OF oDlg
   @ 40,   48 DTPICKER oGet[3] VAR dDat OF oDlg SIZE 60, 10 VALID (MsgBeep(),.T.) PIXEL
   @ 3,    7 BUTTON "&Ok" OF oDlg SIZE 30, 12 ACTION oDlg:End() WHEN .F. // CheckValid(oDlg)
   @ 3,   16 BUTTON "&Cancel" SIZE 30, 12 OF oDlg ACTION oDlg:End() CANCEL  
   ACTIVATE DIALOG oDlg CENTERED

return nil
 


When TAB is used in the Dtepick , NO BEEP !!!!!!!!

THe problem occurs when the next button (ok button) is disabled

Frank
test
Franklin Demont
 
Posts: 166
Joined: Wed Aug 29, 2012 8:25 am

Re: Dtepicker and VALID clausule

Postby Antonio Linares » Tue Nov 12, 2013 3:34 pm

Frank,

I just tried this change but no effect, I keep searching:

Code: Select all  Expand view
METHOD KillFocus( hCtlFocus ) CLASS TControl

   local oWnd

   if ! Empty( hCtlFocus ) .and. ::bValid != nil .and. WndParents( hCtlFocus, ::hWnd ) .and. ;
      ( oWnd := oWndFromhWnd( hCtlFocus ) ) != nil .and. ;
      Upper( oWnd:Classname() ) $ "TBUTTON;TBTNBMP;TBUTTONBMP;TBTNFLAT;TRBTN;TDATEPICK" .and. ;
      ( oWnd:lCancel != nil .and. oWnd:lCancel .and. ;
regards, saludos

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


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 93 guests