Page 1 of 1

Valid clause while inputting data

Posted: Thu Sep 22, 2011 12:21 pm
by concentra
I was unable to find valid clauses while inputting data in TextBoxes used to validate input data, like in Clipper.
Doesn't this exists in HMG3 ?
Or am I missing something ?

Re: Valid clause while inputting data

Posted: Thu Sep 22, 2011 12:49 pm
by Rathinagiri
There are no valid clauses in HMG3, however we can use ONLOSTFOCUS event and SETFOCUS method to validate the textboxes.

Re: Valid clause while inputting data

Posted: Thu Sep 22, 2011 1:28 pm
by mrduck
concentra wrote:I was unable to find valid clauses while inputting data in TextBoxes used to validate input data, like in Clipper.
Doesn't this exists in HMG3 ?
Or am I missing something ?
Since you are posting in HMG4 forum I suppose you are working with version 4.

I already wrote some basic code for VALID, well, 2 versions of it.

In the first version, the background color of the invalid fields is red. You can move to ANY field in ANY order... you have full movement possibilities. This is how a full gui application should behave. Unfortunately porting code from old clipper sources requires we have full control on VALID: the user is not allowed to exit the valid until the content is right...

So the second version uses onLostFocus. You need to use a recent version of Harbour (see hmg4 changelog) and change the final code of Textbox:ProcessTextBoxLostFocus in

Code: Select all

   IF ValType( ::bOnLostFocus ) != 'U' 
      ret := eval( ::bOnLostFocus )
      if valtype( ret ) != "L"
         ret := .T.
      endif
   ENDIF

   if ! ret
      ::setFocus()
      return .T.
   endif

   ::lLostFocusExecFlag := .F.

   RETURN .F.
This code IS NOT fully tested and may have some problems. It uses a FocusOut event, calls the "valid" codeblock and then if the codeblock returns .F. it calls a setFocus() to regain focus.
Unfortunately, it seems that this setFocus generates a FocusOut event from the widget that should get focus and it may create a loop... it must be handled....

Actually, instead of using events it would be better to use subclassing... some c++ samples I found report that they behave correctly and it may solve our problems...
Subclassing c++ means that:
- this special class is added to Harbour (so hmg4 users that want to recompile hmg4 can do it normally)
- this special class is added to HMG4 directly (this requires hmg4 users that want to recompile hmg4 to install Qt SDK and add a directory to the PATH environment variable)

I prefer the second way...

Re: Valid clause while inputting data

Posted: Thu Sep 22, 2011 4:49 pm
by concentra
mrduck wrote:Since you are posting in HMG4 forum I suppose you are working with version 4.
Yes I am.
I questioned the existence in HMG3 because in FiveWin I use this a lot.
I already wrote some basic code for VALID, well, 2 versions of it.

In the first version, the background color of the invalid fields is red. You can move to ANY field in ANY order... you have full movement possibilities. This is how a full gui application should behave. Unfortunately porting code from old clipper sources requires we have full control on VALID: the user is not allowed to exit the valid until the content is right...

So the second version uses onLostFocus. You need to use a recent version of Harbour (see hmg4 changelog) and change the final code of Textbox:ProcessTextBoxLostFocus in

Code: Select all

   IF ValType( ::bOnLostFocus ) != 'U' 
      ret := eval( ::bOnLostFocus )
      if valtype( ret ) != "L"
         ret := .T.
      endif
   ENDIF

   if ! ret
      ::setFocus()
      return .T.
   endif

   ::lLostFocusExecFlag := .F.

   RETURN .F.
This code IS NOT fully tested and may have some problems. It uses a FocusOut event, calls the "valid" codeblock and then if the codeblock returns .F. it calls a setFocus() to regain focus.
Unfortunately, it seems that this setFocus generates a FocusOut event from the widget that should get focus and it may create a loop... it must be handled....
This seems to be what I need.
I will do some testing and will put results here.
Actually, instead of using events it would be better to use subclassing... some c++ samples I found report that they behave correctly and it may solve our problems...
Subclassing c++ means that:
- this special class is added to Harbour (so hmg4 users that want to recompile hmg4 can do it normally)
- this special class is added to HMG4 directly (this requires hmg4 users that want to recompile hmg4 to install Qt SDK and add a directory to the PATH environment variable)
I prefer the second way...
This seems a little to much to me now. I have very few skills in C ...

Re: Valid clause while inputting data

Posted: Thu Sep 22, 2011 5:32 pm
by concentra
Francesco,
mrduck wrote:This code IS NOT fully tested and may have some problems. It uses a FocusOut event, calls the "valid" codeblock and then if the codeblock returns .F. it calls a setFocus() to regain focus.
Unfortunately, it seems that this setFocus generates a FocusOut event from the widget that should get focus and it may create a loop... it must be handled....
This potential loop situation can be handled by a shared var, and yes, I now this isn't the most elegant solution.

This shared var is settled true whenever a ProcessXxxxLostFocus HMG4 event is started and settled false when finished.
And when another ProcessXxxxLostFocus HMG4 event is started before the current one finishes, it verify this flag and, if it settled, abandon processing.

Re: Valid clause while inputting data

Posted: Thu Sep 22, 2011 6:30 pm
by mrduck
concentra wrote: This shared var is settled true whenever a ProcessXxxxLostFocus HMG4 event is started and settled false when finished.
And when another ProcessXxxxLostFocus HMG4 event is started before the current one finishes, it verify this flag and, if it settled, abandon processing.
Please try AND NOT commit moving

Code: Select all

::lLostFocusExecFlag
in globshared.