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

Does Read Events work differently when Show Window = 0? 1

Status
Not open for further replies.

TomLeMes

MIS
Mar 19, 2004
96
GB
Having made a pretty good start on my application, I've now been told that the bosses want all forms to be placed within a 'containing' form so that all the different screens that come and go as the user moves around the app are in the one place.

So I changed my form classes to have a ShowWindow property of 0 (in Screen), removed _screen.visible = .f. from my main.prg and all seemed fine - they all appear within the VFP screen (I put in some other code to put in a nice background graphic on the _screen and hide any menus etc.)

Except that now Read Events/Clear events seems all messed up. I have a standard call to my login form:
Code:
ON SHUTDOWN do ShutdownProc in .\progs\shutdn.prg
[green]*some code here to remove statusbar, disable close buttons etc.[/green]
DO FORM .\forms\MF_login
READ events
The big problem comes when I want to either release a form or close down the application altogether (this was working fine before). Before if I clicked the cancel button on my login form the code thisform.release would run and then my shutdown procedure would kick in. Now the loginform releases, but then I'm just stuck with my VFP window

I suppose this becuase I still have a form (the main VFP window) open, so the on shutdown event hasn't triggered. What I did find is that by taking out the READ EVENTS line I could almost get things working, but then the problem would be that releasing one form would close down the whole application! Sorry, I know the whole Read Events/Clear Events comes up a lot and I've been bombarding you guys recently, but this is really confusing me. Any help would be great. Thanks,

Tom
 

Tom,

You're nearly there. Basically, you need to put a CLEAR EVENTS in the shutdown code, that is, in the Close button of the form, or the File / Exit command, or the Destroy of the form, or any other place where a closedown might be triggered.

CLEAR EVENTS will pass control to the line after the READ EVENTS. You should put any clean-up code at that point.

Hope this helps.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My sites:
Visual FoxPro (www.ml-consult.demon.co.uk)
Crystal Reports (www.ml-crystal.com)
 
Thanks Mike, I can see that that should work - makes sense! But here is my actual startup code
Code:
ON SHUTDOWN do ShutdownProc in .\progs\shutdn.prg

_SCREEN.WindowState = 0	
APPLICATION.Height = 600
APPLICATION.Width = 800
APPLICATION.Left = 0
APPLICATION.Top = 0

SET STATUS BAR off
SET TALK OFF

DO FORM .\forms\MF_login
READ events

MESSAGEBOX('Control has returned')
DO ShutdownProc
Problem is that the messagebox (not to mention the shutdown code) never gets run. The code behind the Cancel button on my login box simply says
Code:
thisform.release
CLEAR EVENTS
I've put messageboxes in the login form's RELEASE and DESTROY events and they *are* happening, but control never returns to the prog. If I check the VFP program menu the only options enabled are Cancel and Suspend, so it seems like we're still in the event loop (or something?). When I click the Cancel button I get a Wait Window that says "Do Cancelled". Oh, and when I run through the code step by step it seems fine until it returns to the main.prg where it (the yellow arrow) just sits at the READ EVENTS line again. Is there anything I can do to check what it's waiting for?

My hunch is that this is related to my switch from Top-level forms to In-Screen forms, but other than that I'm still puzzled.
 

Tom,

Is this a modal form, by any chance? That might explain the behaviour you are seeing. Also, it ties in with the switch from Top-level to In-Screen. Might be worth checking.

If that doesn't help, I suggest you try putting the CLEAR EVENTS in the form's Destroy.

By the way, you say that the yellow arrow is sitting at READ EVENTS. That's normal. It just means that the app is waiting for user input.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My sites:
Visual FoxPro (www.ml-consult.demon.co.uk)
Crystal Reports (www.ml-crystal.com)
 
Oh my, it was as simple as that! Thank you very much - it all works like a dream now. Like you say, I was nearly there!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top