Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Running a form from another form
Message
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Miscellaneous
Thread ID:
00246479
Message ID:
00246516
Views:
15
>From form #1, I am running form #2 with the click of a command button.
>In the click method on form #1 that calls form #2, there is code that should execute AFTER form #2 is finished. But it is not waiting for form #2 to run before it executes. Why?

Unless the second form is created as a modal form, the first form continues right along in its code.

If the second form must be run to comnpletion before other procesing can continue, then the easiest thing to do will be to make the second form modal by setting the form's WindowType property to 1 (modal).

If you can't make the form modal for some reason, you'll need to add code to the first form to wait on the other form to complete. One mechanism to do this would be to create a property in Form1 that is set before starting Form2. Pass a reference to Form1 to Form2 in the DO FORM statement, and have Form2 change the property in Form1 when it is ready to close. If you add a Form property to Form1 called lWaitingOnForm2, your code might look like:
*Form1's launch of Form2:
this.lWaitingOnForm2 = .t.
DO FORM Form2 WITH this
DO WHILE this.WaitingOnForm2
   DOEVENTS
ENDDO

*Form2's Init;  I've assumed you would add a property to hold
* the form reference passed by the caller
LPARAMETER toParent
this.oParentForm = toParent  && save object reference if passed

*Form2's Release
IF TYPE('this.oParentForm.lWaitingOnForm2') = 'L'
   this.oParentForm.lWaitingOnForm2 = .f.  && update object if ref saved and property exists
ENDIF
this.oParentForm = .F.
Be aware that this results in a tight coupling of Form1 and Form2; as a result, any form that uses Form2 will need to have an lWaitingOnForm2 property added to it to provide the semaphoring mechanism. Modal operation will be more portable, and would allow you to explicitly return a value if needed without having to pass the form reference.
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Previous
Reply
Map
View

Click here to load this message in the networking platform