Valid clause while inputting data

Moderator: Rathinagiri

Post Reply
User avatar
concentra
Posts: 256
Joined: Fri Nov 26, 2010 11:31 am
Location: Piracicaba - Brasil

Valid clause while inputting data

Post by concentra » Thu Sep 22, 2011 12:21 pm

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 ?
[[]] Mauricio Ventura Faria

User avatar
Rathinagiri
Posts: 5246
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Has thanked: 165 times
Been thanked: 164 times
Contact:

Post by Rathinagiri » Thu Sep 22, 2011 12:49 pm

There are no valid clauses in HMG3, however we can use ONLOSTFOCUS event and SETFOCUS method to validate the textboxes.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.

mrduck
Posts: 497
Joined: Fri Sep 10, 2010 5:22 pm

Post by mrduck » Thu Sep 22, 2011 1:28 pm

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...

User avatar
concentra
Posts: 256
Joined: Fri Nov 26, 2010 11:31 am
Location: Piracicaba - Brasil

Post by concentra » Thu Sep 22, 2011 4:49 pm

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 ...
[[]] Mauricio Ventura Faria

User avatar
concentra
Posts: 256
Joined: Fri Nov 26, 2010 11:31 am
Location: Piracicaba - Brasil

Post by concentra » Thu Sep 22, 2011 5:32 pm

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.
[[]] Mauricio Ventura Faria

mrduck
Posts: 497
Joined: Fri Sep 10, 2010 5:22 pm

Post by mrduck » Thu Sep 22, 2011 6:30 pm

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.

Post Reply