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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Timer messing up two combo boxes

Status
Not open for further replies.

torturedmind

Programmer
Jan 31, 2002
1,052
PH
Good day to all.

I just wanted to share my experience with a shutdown timer. The app was running smoothly until I dropped a timer (shutdown) on the main form in the main app. The problem was two of the combo boxes, both used to select names of initial approval and final approval respectively) in the sub apps behaved strangely all of a sudden. On LOSTFOCUS, both combo boxes always point to the first item (LISTINDEX is always 1) even when the user already selected an item from the drop-down list. No code was written in the LOSTFOCUS event nor there are LISTINDEX = 1 command in any part of the app. What I did to avoid this strange behavior was to ENABLED = .F. the shutdown timer in the WHEN event of both combo boxes then ENABLED = .T. in the LOSTFOCUS event. I know this somehow defeats the purpose of the shutdown timer if the user just stayed within any of the two combo box controls because the shutdown timer won't be enabled until the user leave the said controls. Did anyone ever encountered such behavior? Anyone else got better ideas than what I did?

TIA

kilroy [knight]
philippines

"Once a king, always a king. But being a knight is more than enough."
 
What is the shutdown timer doing? Is it activating some workarea? Then that could be the problem. Your shutdown timer code needs to be very clean and reset everything it changes.

Bye, Olaf.
 
Apologies for the late reply as we were having problems with our ISP with the frequent typhoons and all.

What is the shutdown timer doing? Is it activating some workarea?
The Timer event just perform the usual housekeeping routines before closing the app. There is no SELECTing work areas or something similar.

Is there any sort of REFRESH or SETFOCUS code in the timer?
There is none.

I also read here that there are some problems with ON KEY LABEL on COMBOBOXes. I dunno but it could be another adverse effect(?)

kilroy [knight]
philippines

"Once a king, always a king. But being a knight is more than enough."
 
I also read here that there are some problems with ON KEY LABEL on COMBOBOXes. I dunno but it could be another adverse effect(?)

In general, you should avoid ON KEY LABELs. They're not a good idea. I definitely wouldn't use one with a combobox. What are you trying to accomplish? (Whatever it is, the KeyPress method is almost certainly a better choice.)

Tamar
 
I think I should have mentioned in my original post that I'm using Ramani's faq184-4467 Currently, I'm using the method I mentioned in my original post to circumvent the issue. I know it's not that elegant nor fully fool-proof. But as of the moment with some tweaking, it works. I just wish there's better way to do this. [ponder]


kilroy [knight]
philippines

"Once a king, always a king. But being a knight is more than enough."
 
How about not making us guess the details you haven't shared.

Can you post the code from your timer method? If it's too long to post here, it's too long.
 
My honest apologies to all. I just thought that since I mentioned that the problem involves a shutdown timer, it's a dead giveaway that it's all about shutting down an app on some specific amount of time of inactivity. Anyway, here is the code:

Code:
PRCOEDURE Timer1.TIMER
IF ((DATETIME() - dtlastused) * 1000) > (THIS.INTERVAL * 2)
	CLEAR EVENTS
	THISFORM.RELEASE()
	appshutdown()
ENDIF
ENDPROC

FUNCTION appshutdown
FormRelease2()

IF TYPE("p_connect") = "N" ;
		AND p_connect > 0
	SQLDISCONNECT(p_connect)
ENDIF

RELEASE ALL EXTENDED
CLEAR PROGRAM
CLEAR ALL
CLOSE ALL
QUIT
ENDFUNC

FUNCTION FormRelease2
FOR EACH loForm IN _SCREEN.FORMS
	loForm.RELEASE()
ENDFOR
ENDFUNC


kilroy [knight]
philippines

"Once a king, always a king. But being a knight is more than enough."
 
I don't see how that could effect the comboboxes. Can you really reproduce the unwanted behavior by keeping the timer enabled?

Normally all that runs in the timer is the IF, which evaluates to .F. and doesn't run its code. Otherwise your app finishes and you won't see any effect on comboboxes. As a sidenote: If it does, I wouldn't run the appshutdown() call in the timer, that should be put after READ EVENTS. If you do it in the timer, you won't need the form release call, that's done by FormRelease2 for all forms including this one.

You spoke about ON KEY LABEL in conjunction with the comboboxes, what do the keys do with the combobox? Are you in any way defining something for ESC or ENTER? And do you have a button with cancel=.t. or default=.t.? These buttons are typically used as cancel/close buttons of a form and can be triggered by ESC and ENTER, but they also cause these keys. Some frameworks make use of that in skipping validation code in case LASTEKY()=27, which works both for users pressing ESC or clicking the cancel button. That way the cancel button can get focus, no matter if the currently edited control has an invalid value or not, which is unimportant, as the typical cancel button functionality will revert that change anyway.

ON KEY LABELs are a bad instrument for defining something for a specific control, as their triggered code runs outside of form scope. And they are perhaps even not defined in the comobobox init/when/gotfocus, so it's not obvious they have their effect. If something is wrong with a control behaviour the first thing you look at is that controls code. So at least I would expect a comment about ON KEYs defined for the control as a pointer for what to investigate. If ON ESCAPE is defined to reset to listindex=1 and you have a cancel button in the form, that would cause it, for example, and wouldn't be so obvious. ON KEY LABEL ENTER or RETURN would cause it together with a default button.

Bye, Olaf.
 
By the way: why I asked: A shutdown timer might also look for a signal to shutdown in some table and therefore use that and change the active workarea. That's why I asked that. It#s not a natural a shitdown timer just does it's thing after some inactivity.

By the way: you could set the timer interval to the interval you want as max accepted inactivity and instead of setting dtlastused call the RESET method of the timer. Then the timer code would just need to be CLEAR EVENTS or QUIT.

Bye, Olaf.
 
And finally: One reason your code about deactivating the timer in When and LostFocus just seems to solve your problem: You're overloading some inherited code in the combobox class you suppressed this way. So are these comboboxes native comboboxes or do they have a parentclass? If so, what#s in the parent class When and LostFocus.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top