Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to trap a change in a ListBox after a MESSAGEBOX()
Message
From
11/03/2016 15:07:58
Lutz Scheffler
Lutz Scheffler Software Ingenieurbüro
Dresden, Germany
 
 
To
11/03/2016 14:56:17
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows 10
Miscellaneous
Thread ID:
01632877
Message ID:
01632878
Views:
58
>Dear All
>
>I'm stuck with two minor but still annoying glitches in a form, and hoping that someone can help me to sort it out.
>
>In the form there is a list that is keeping track of the current item. When the user clicks on an item, the list value is changed, as usual.
>
>The first problem is that a) if the list does not have focus, b) and the user leaves the control that has focus by clicking an item in the list, c) and a message box is issued during the event sequence that goes before focus is passed to the list, the list value and its index are not changed.
>
>The second problem occurs, after the above sequence, a) if the focus goes back to the other control, the highlighted item is recoordinated with the list value and index (we could consider that this is not a problem at all, since at least value and highlight are now in sync, but this change is made without direct user intervention).
>
>Hopefully, the following program will help me to demonstrate this:
>
>
>LOCAL loForm AS aForm
>
>m.loForm = CREATEOBJECT("aForm")
>
>m.loForm.Show(1)
>
>DEFINE CLASS aForm AS Form
>	ADD OBJECT theList AS aList
>	ADD OBJECT theText AS aTextBox WITH Left = 100
>ENDDEFINE
>
>DEFINE CLASS aList AS ListBox
>
>	PROCEDURE Init
>
>		This.AddItem("Item 1")
>		This.AddItem("Item 2")
>		This.AddItem("Item 3")
>		This.ListIndex = 1
>
>	ENDPROC
>
>	PROCEDURE InteractiveChange
>
>		WAIT WINDOW "InteractiveChange(): " + TRANSFORM(This.ListIndex) + "/" + This.Value NOWAIT NOCLEAR
>
>	ENDPROC
>
>	PROCEDURE ProgrammaticChange
>	
>		WAIT WINDOW "ProgrammaticChange(): " + TRANSFORM(This.ListIndex) + "/" + This.Value NOWAIT NOCLEAR
>
>	ENDPROC
>
>	PROCEDURE Click
>
>		WAIT WINDOW "Click(): " + TRANSFORM(This.ListIndex) + "/" + This.Value NOWAIT NOCLEAR
>
>	ENDPROC
>
>ENDDEFINE
>
>DEFINE CLASS aTextBox AS TextBox
>
>	PROCEDURE Valid
>
>		IF !EMPTY(This.Value)
>			MESSAGEBOX("Some validation...")
>		ENDIF
>
>	ENDPROC
>
>ENDDEFINE
>
>
>Steps to reproduce it:
>1. Run the program
>2. Click on the list items, the information window is updated.
>3. Enter the textbox, leave it empty, and return to the list. All is ok.
>4. Enter the textbox again, but insert some characters.
>5. Click on a different item in the list. A message box pops up. Click Ok.
>6. First problem: the highlighted item in the list is the one clicked on step 5, but the list value and index do not change.
>7. Enter the textbox again.
>8. Second problem: the highlight moves by itself.
>
>Am I doing anything wrong, here? Is there a way this can be circumvented?

Not realy related but skip the use of those wait window. Start debugger and use DEBUGOUT. This will not move focus. Also if you miss to remove, it will not harm in runtime. Even if you use a hand axe like VFP, there is no need to stuck to outdatded debugging tools.

In general, a Messagebox will play araound with active windows. So If you call a Messagebox, your form will be deactivated , messagebox will shown and form will be activated after. What means gotfocus events and whatever might fire too. Check EVENTLOGGING (but this is a pain)

Try to run your code without the messagebox, just with a ? or a debugout for testing, if this runs, your problem is related to focus problems as mentioned above.

In general validating while input is a pain. I validate on records tableupdate level, much less fuss. (To me)
Words are given to man to enable him to conceal his true feelings.
Charles Maurice de Talleyrand-Périgord

Weeks of programming can save you hours of planning.

Off

There is no place like [::1]
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform