Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Valid or whatever, revisited
Message
From
13/04/1998 15:20:32
Dragan Nedeljkovich
Now officially retired
Zrenjanin, Serbia
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Title:
Valid or whatever, revisited
Miscellaneous
Thread ID:
00091590
Message ID:
00091590
Views:
49
Back to an old issue (I started a bit of it in another thread couple of days ago, but I think it needs a new thread. I need it :).

Question: field validation within a control AND from the save button (both). The desired behavior is to enable validation if field is exited via regularly typing until it's full, or if the user edits it any way, and to skip validation if user didn't change the value, or a nav button is clicked on. The exception to this is that form.SaveRec method will call validation for itself. It will not call control.valid, it will call control.localvalid (defined at control class level) and set focus back to any control which returns false or 0; regular valid also calls this. BTW, is this the famous hook technology?

Now the trouble is that the valid method (or lostfocus as well) doesn't know why it was invoked - is it one of the "edited and finished" cases, or "interrupted the edit by clicking on a nav button or close box". I've logged the events, and here's what happens:

[Clicking on the textfield:]
form.txt1.GotFocus()
form.txt1.Message()
form.txt1.MouseDown(1, 0, 30,83, 1,56)
form.Paint() (I was a bit curious why is this method invoked, but then I got it - it's for controls which change appearance whrn they receive focus)
form.txt1.MouseUp(1, 0, 30,83, 1,56)
form.txt1.Click()

[these two repaints beat me; I'd understand one, but two... probably the second happens when I click on the nav button . It was the exit button this time, for simplicity's sake]
screen.Paint()
screen.Paint()

[Now it tries to leave the textbox; I tried to put some code into form.navbuttons.GotFocus() to set a form's EditingIsOn property to .f., but it fires later, so it's no use]
form.txt1.RangeLow()
form.txt1.RangeHigh()
form.txt1.Valid()

[Now this may be my only chance to get something done before the last method of form.txt1 fires]
form.navbuttons.cmdexit.When()
[And finally the last chance fires. Is this the reason why all the folks here said that Valid is legacy and the validation should be moved to .lostfocus - it fires after some of the next control's methods, so we can establish some inter-control communication?]
form.txt1.LostFocus()

[And finally the clicked nav buttons methods fire.]
form.navbuttons.GotFocus()
form.navbuttons.cmdexit.GotFocus()
form.navbuttons.cmdexit.MouseDown(1, 0, 85,17, 12,94)

...etc. Now is there any better solution than to replicate the signalling code (thisform.EditingIsOn=.f.) in every nav button's .When(), and to move all the validation to txt*.lostfocus, or try another approach? I have another idea - to have an indicator property of IAmChanged on every control, and set it to .t. from .InteractiveChange and .ProgrammaticChange, and fire the validation when this property is set to .t., else just return .t. from the .valid event? I'll try both tonight, but in the meantime, if anyone has something better than these two, I'm very curious to know. TIA

back to same old

the first online autobiography, unfinished by design
What, me reckless? I'm full of recks!
Balkans, eh? Count them.
Next
Reply
Map
View

Click here to load this message in the networking platform