HARD VALID implemented

Moderator: Rathinagiri

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

HARD VALID implemented

Post by mrduck »

A while ago I was asked by a friend if it would be possible to clone harbour VALID functionality in hmg4.
At first I was contrary since it is against GUI standards... you can't be forced on a field if there are other active fields on the form.
Then he convinced me saying that also my harbour text-mode code heavily relies on VALIDs and their side-effect (f.e. record pointer moves).

It is not easy to do in Qt, just because it is not standard GUI behaviour ! And Qt doesn't ask "I want to leave the object, can I ?" It just moves the focus and generates events and signals...

Well, I must advise you that using the HMG3 way to use :setFocus() inside a onLostFocus event may not work in HMG4 ! :setFocus() can't be used safely in the lost focus event.

So I used a little trick: keep record of the object losing focus with a VALID not true and on the onGotFocus of the next textbox check if we must give focus back to someone else...

Up to now it seems to work in a very simple, little test, with only a widget in the form with a VALID... The test must be expanded to accomodate several other complex situations... (I already know that current code can fail in some cases...)

From samples\hardvalid\demo_1.prg

Code: Select all

      With Object o2 := textbox():New()
         :Value    := 'must be PIPPO'
         // :onValid := {|| o2:value == "PIPPO" }
         :onValid := {|| hb_QWith():value == "PIPPO" }
         :tooltip := "You must enter <b>PIPPO</b> to move from this textbox"
      End With
This commit is also important for other points:
- started using of HB_TRACE for helping debugging... this is absolutely transparent to library users since the trace must be enabled during library compilation...
- started to add some docs in the code to explain what that code does... too much time spent to guess what a piece of code written a month ago actually does...
- introduced calling a code block nested in a WITH OBJECT Self

Code: Select all

 WITH OBJECT Self; ret := eval( ::bOnValid ); END
Using EVAL we lose the calling object. If you look at the example above in the remmed onValid I have to specify the variable name... it's ok, of course.... in the second sample we retrieve the current object with hb_QWith()... probably I could have used the new methods introduced by Luigi to know the current object, but I wrote the code before his commits...

I still think that hard valids are not GUI standard and they are BAD... I know that committed code needs to be updated for handling more complex cases... I already know how to visually signal that a textbox has invalid value (via css selectors - great Qt power !!!)

Now I ask you to report your ideas on this feature.
User avatar
Roberto Lopez
HMG Founder
Posts: 4004
Joined: Wed Jul 30, 2008 6:43 pm

Re: HARD VALID implemented

Post by Roberto Lopez »

mrduck wrote:Now I ask you to report your ideas on this feature.
Is a great feature.

It was asked to me for years by the users.

I'm sure that everybody will love it.

Regarding 'standards', Visual FoxPro included it, so HMG.4 will be not alone on this :)
Regards/Saludos,

Roberto


(Veritas Filia Temporis)
User avatar
l3whmg
Posts: 694
Joined: Mon Feb 23, 2009 8:46 pm
Location: Italy
Contact:

Re: HARD VALID implemented

Post by l3whmg »

Hi.
Good news and good perspective.
I must understand well, but I think ...good!

Cheers
Luigi from Italy
www.L3W.it
mrduck
Posts: 497
Joined: Fri Sep 10, 2010 5:22 pm

Re: HARD VALID implemented

Post by mrduck »

Yesterday night I added a nice features... if the valid is .F. text turns red.... I need some more tuning then I'll commit...

Francesco

l3whmg wrote:Hi.
Good news and good perspective.
I must understand well, but I think ...good!

Cheers
Post Reply