ON CHANGE in tGet

Postby James Bott » Thu Jul 26, 2007 11:40 pm

Enrico,

>Just check oGet:oGet:HasFocus. It is .T. in bLostFocus and .F. in bValid.

Thanks for clarifying that. That may be correct but it is unexpected.

Tim,

Perhaps you can use bLostFocus instead of bValid to solve your problem?

James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Postby Enrico Maria Giordano » Fri Jul 27, 2007 11:08 am

James Bott wrote:Thanks for clarifying that. That may be correct but it is unexpected.


I agree. Antonio?

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8716
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby James Bott » Fri Jul 27, 2007 2:02 pm

It seems that this must be causing some undesirable effects. If bValid is not eval'd until AFTER the control looses focus, then bLostFocus has already been eval'd and then if bValid fails, then bGotFocus is going to be eval'd too, even though, theoretically you have never left the control.

bValid should be getting eval'd before the control looses focus and it should not loose focus until bValid returns .t. --at least this seems to be the correct behavoir to me.

James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

OK

Postby TimStone » Fri Jul 27, 2007 6:07 pm

I got around the problem but as James says, there may be a bug to review in this case.
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
TimStone
 
Posts: 2944
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Postby Otto » Thu Dec 27, 2007 6:40 pm

Hello James,


>Just check oGet:oGet:HasFocus. It is .T. in bLostFocus and .F. in bValid.

If I have two get-fields where I check if the end-date is later I think you need such a behavior.
If I jump to the start field then I need a return .t. and no checking.
Is there another way to bypass the checking?

Regards,
Otto

GET oGetStart
GET oGetEnd VALID ( check() )


func check()
if oGetAnkunft:oGet:HasFocus=.t.
retu (.T.)
endif

if dStart > dEnd
MsgInfo(" dStart > dEnd ")
retu (.F.)
endif

retu (.T.)
User avatar
Otto
 
Posts: 6332
Joined: Fri Oct 07, 2005 7:07 pm

Postby James Bott » Thu Dec 27, 2007 9:27 pm

Otto,

I'm not sure I understand what you are trying to do. Wouldn't this work? Why do you need to check for focus?

James


Code: Select all  Expand view  RUN
GET oGetStart
GET oGetEnd VALID ( check() )

func check()
   if dStart > dEnd
      MsgInfo(" dStart > dEnd ")
      retu (.F.)
   endif
retu (.T.)
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Postby Otto » Thu Dec 27, 2007 9:52 pm

For example: as default I use today and today + 7 days.
If I begin editing in the end get field and I choose a date before the start date there is not possibility to jump to the start date to change this value too.
Regards,
Otto
User avatar
Otto
 
Posts: 6332
Joined: Fri Oct 07, 2005 7:07 pm

Postby Patricio Avalos Aguirre » Thu Dec 27, 2007 9:59 pm

Saludos
Patricio

__________________________________________________________________
Version: Harbour 3.2.0dev (r1307082134),Compiler: Borland C++ 5.8.2 (32-bit)
PCode version: 0.3, FWH 13.2
http://www.sialm.cl
User avatar
Patricio Avalos Aguirre
 
Posts: 1060
Joined: Fri Oct 07, 2005 1:56 pm
Location: La Serena, Chile

Postby James Bott » Thu Dec 27, 2007 10:21 pm

Otto,

>If I begin editing in the end get field and I choose a date before the start date there is not possibility to jump to the start date to change this value too.

There seems to be a circular logic problem here. When start > end then EITHER the start is wrong, the end is wrong, or they are both wrong. So doing a valid on the end date presents you with the problem of figuring out which date needs to be changed. Jumping to the start date MAY be the right solution or not--there is no way to know. Plus, as you pointed out, you can't leave the end field until it is valid and it can't be valid unless it is greater than the start. Thus the Catch-22.

I would color the background of both fields pink when start > end, and popup a tooltip explaining the problem. I would use bPostEdit to trigger this action on both GETs. This way the user can edit either field to get the backgrounds to turn white again (valid). I wouldn't use a VALID since you want the user to be able to exit one field to edit the other. And they can go back and forth between the fields until they are right. The color and the tooltip give them visual indications of the problem without presenting them with a msg that they have to click to get rid of.

Also you could do a validity check when the dialog is closed to make sure the two fields are valid before saving.

James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Postby Otto » Thu Dec 27, 2007 10:38 pm

Thank you James for you explanation. I will give your suggestion a try.
User avatar
Otto
 
Posts: 6332
Joined: Fri Oct 07, 2005 7:07 pm

Postby James Bott » Thu Dec 27, 2007 10:48 pm

Otto,

Here is some sample code to get you started.

James

Code: Select all  Expand view  RUN
#include "wcolor.ch"

#define COLOR_CRITICAL Rgb(255,197,255) // backround color of critical data - Pink


oGetStart:bPostEdit := {|oGetStart,oGetEnd| checkDates(oGetStart,oGetEnd) }
oGetEnd:bPostEdit :=   {|oGetStart,oGetEnd| checkDates(oGetStart,oGetEnd) }


function checkDates(oGetStart,oGetEnd)
   if oGetStart:varGet() > oGetEnd:varGet()
      oGetStart:setColor( COLOR_TEXT, COLOR_CRITICAL )
      oGetEnd:setColor( COLOR_TEXT, COLOR_CRITICAL )
   else
      oGetStart:setColor( COLOR_TEXT, COLOR_WINDOW )
      oGetEnd:setColor( COLOR_TEXT, COLOR_WINDOW )
   endif
   oGetStart:refresh()
   oGetEnd:refresh()
return nil
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Postby James Bott » Thu Dec 27, 2007 11:00 pm

Otto,

Here is an improved version--not tested.

James
Code: Select all  Expand view  RUN
#include "wcolor.ch"

#define COLOR_CRITICAL Rgb(255,197,255) // backround color of critical data - Pink


oGetStart:bPostEdit := {|oGetStart,oGetEnd| checkDates(oGetStart,oGetEnd) }
oGetEnd:bPostEdit :=   {|oGetStart,oGetEnd| checkDates(oGetStart,oGetEnd) }


function checkDates(oGetStart,oGetEnd)
   if oGetStart:varGet() > oGetEnd:varGet() .and. ! empty( oGetEnd:varGet() )
      oGetStart:setColor( COLOR_TEXT, COLOR_CRITICAL )
      oGetEnd:setColor( COLOR_TEXT, COLOR_CRITICAL )
      oGetStart:cTooltip:= "Start date cannot be later than end date."
      oGetEnd:cTooltip:="Start date cannot be later than end date."
   else
      oGetStart:setColor( COLOR_TEXT, COLOR_WINDOW )
      oGetEnd:setColor( COLOR_TEXT, COLOR_WINDOW )
      oGetStart:cTooltip:=nil
      oGetEnd:cTooltip:=nil
   endif
   oGetStart:refresh()
   oGetEnd:refresh()
return nil
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Postby James Bott » Thu Dec 27, 2007 11:08 pm

Otto,

Silly me. You can also do this with a VALID clause.

redefine get oGetStart...valid checkDates(oGetStart,oGetEnd)

Then just return .t. from the checkDates function (instead of nil). It should work just the same as using bPostEdit.

James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Postby James Bott » Fri Dec 28, 2007 11:44 pm

Otto,

OK, here is a tested working example.

James


Code: Select all  Expand view  RUN
#include "fivewin.ch"
#include "wcolors.ch"

#define COLOR_CRITICAL Rgb(255,197,255) // backround color of critical data - Pink


function main()
   local oDlg, oGetStart, oGetEnd
   local dStart:= ctod("09/09/09"), dEnd:=ctod("  /  /  ")
   set epoch to 1980

   define dialog oDlg title "Test Date field valids"

   @ 2,2 Get oGetStart var dStart of oDlg valid checkDates( oGetStart, oGetEnd )
   @ 3,2 Get oGetEnd var dEnd of oDlg valid checkDates( oGetStart, oGetEnd )

   activate dialog oDlg centered

return nil

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

function checkDates(oGetStart,oGetEnd)
   local nClrFore:=getSysColor( COLOR_WINDOWTEXT ), nClrPane:= getSysColor( COLOR_WINDOW )
   if oGetStart:varGet() > oGetEnd:varGet() .and. ! empty( oGetEnd:varGet() )
      oGetStart:setColor( nClrFore, COLOR_CRITICAL )
      oGetEnd:setColor( nClrFore, COLOR_CRITICAL )
      oGetStart:cTooltip:= "Start date cannot be later than end date."
      oGetEnd:cTooltip:="Start date cannot be later than end date."
   else
      oGetStart:setColor( nClrFore, nClrPane )
      oGetEnd:setColor( nClrFore, nClrPane )
      oGetStart:cTooltip:=nil
      oGetEnd:cTooltip:=nil
   endif
   oGetStart:refresh()
   oGetEnd:refresh()
return .T.

//----------------------------------------------------------------------------//
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Postby Otto » Sat Dec 29, 2007 5:24 pm

Thank you, James.

Please have a look at: www.fwcodesnips.com
User avatar
Otto
 
Posts: 6332
Joined: Fri Oct 07, 2005 7:07 pm

Previous

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 60 guests