Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Container LostFocus() is executing a misfired Click Event from the button it suppose to focus to

Status
Not open for further replies.

pettrip

Programmer
May 5, 2013
2
PH
I know subject is confusing let me explain.

I have a Class (Address) with validation codes in its Container LostFocus Event
which validates the values of objects (e.g. txtbox, combobox) in the container.

When I edit the values on the Address Class and Click another Button outside of the Class
which triggers the Address Class LostFocus Event, validates the Values of its object
If any of the Values are invalid return .f. in the lostfocus event and focus on the invalid value.

The issue is that the Click Event of the button is firing even if the whole LostFocus routine is executing
It somehow gets inserted before the LostFocus is done.

This is only encountered on the second try,
where the user's address is invalid, clicks in the button and choose to change to an invalid address
and click on the button again

Class Container LostFocus Methsd
This.AddrValid = .t.
if !This.IsValidAddress() -- > This shows a message “Do you want to update the Address? Y/N”
   This.TxtAddress.SetFocus()
   This.AddrValid = .f.
endif

(<----Somehow the Click Event of the Button is misfiring here)

if This.AddrValid
   return .t.
else
   nodefault
   return .f.
endif

Any help is deeply appreciated, as I have no idea why this is happening

 
Hi

Are you sure that is the place that click event is firing? VFP is single threaded so the only way it could happen there would be
if there was a MyButton.Click() in the code.

I would suggest that you rework the code slightly so you can have just one 'exit' and either use the debugger or a simple text log to
follow the flow of the code (you would need to put code into the button click event too to log it's action.

So, I would declare a public handle for a file, open it before you initialise the container and write lines to it as I progress through the LostFocus method..

Then run your program, shut it down and examine the file for clues.

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
 
Have I got this right? You are saying that the button's Click event is firing while the code in the LostFocus is executing? That the Click somehow interrupts the LostFocus?

If that's what you mean, I have to ask if you are sure that that is what you are seeing. I've never seen that behaviour before, and I can't see how it can be possible. As far as I know, the only times when code might be interrupted in that way is if a timer is firing, or if you have an ON KEY LABEL, but you haven't mentioned either of those two possibilities.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Wow, snap Mike!

I don't think a timer CAN fire while code is executing - the timer stops because VFP is single threaded.
I also suspect an ON KEY would require some kind of wait state (inkey() or similar) to be fired too.

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
 
Let's say text1 is in the container and a button command2 is outside, text1 has focus, command2 is clicked.

Then these events happen (recorded with event tracking);

form1.container1.text1.Valid()
form1.command2.When()
form1.container1.text1.LostFocus()
form1.container1.LostFocus()
form1.command2.GotFocus()
form1.command2.Click()

So command2.Click() should happen after coontainer1.LostFocus(), you shouldn't have a problem.
I think using a Messagebox in the IsValidAddress code changes event order and causes further events, as you have a deactivate and activate of the form and more control focus related events.
Event tracking should tell you what happens in which sequence. You should SET EVENTLIST, SET EVENTTRACKING TO a log file, and SET EVENTTRACKING ON in the form.Load(), then SET EVENTTRACKING OFF in the form.Unload().

Then look into the file and see where your validation can be done to have the desired effect.

Chriss
 
HI

Thanks for the replies
Yes I don't have timers or any ON KEY
As pointed by Chris Miller on the routine

form1.container1.text1.Valid()
form1.command2.When()
form1.container1.text1.LostFocus()
form1.container1.LostFocus() -> at this point if the text1 value is invalid, refocus on the Text1 otherwise proceed, but the form1.command2.Click() is misfiring here
form1.command2.GotFocus()
form1.command2.Click()

On the form1.container1.LostFocus() section the form1.command2.Click() is firing.
I added a messagebox("Start") at the beginning of the form1.container1.LostFocus()
and messagebox("End") at the end of the LostFocus. And also added a messagebox("Click") in the form1.command2.Click()
and yes the Sequence I'm getting is Start->Click->End.

I'll try Chris Miller's suggestion on a more comprehensive Log Tracking and see as to what really is happening

Thank you so much for the help


 
Messageboxes are really not good for finding out event order, as the messagebox is a separate form, which causes focus related events, if events are not logged only put in some code having no effect, like just a LOCAL var declaration.

Chriss
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top