Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Syntax, Scope or Stupidity?
Message
From
28/12/2010 11:53:41
 
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Miscellaneous
Thread ID:
01494008
Message ID:
01494015
Views:
74
>>Re: Thread ID: 1473802
>>I have 2 modeless forms open and I run the following code:
>>
>>Both appear as open forms in the messagebox below, but I cannot programatically close the one called OrderEntry_Scx.
>>
>>Can you help? Thank you!
>>
>>
>>
>>	FOR EACH loForm In _Screen.Forms
>>		=Messagebox('Here is the form: ' + loForm.Name)
>>		 IF loForm.caption = 'OrderEntry_Scx'
>>			 	*!* loForm.Release()
>>			 	*!* loForm.Name.Release()
>>			 	*!* OrderEntry_Scx.Release()
>>			 	*!* loForm.Release 
>>			 	*!* loForm.Name.Release 
>>			 	*!* OrderEntry_Scx.Release 
>>		 ENDIF
>>	NEXT 
>>
>
>The reason for this problem as you can not remove an object from collection using FOR EACH loop. This problem was discussed here before and I admit I made the same mistake myself (and may be twice even). You need to loop using counter and from the last record to the first.
>
>Check How can I release all open forms FAQ #7975 It shows the main principle, you need to adapt that code for your case.

Not sure how the above would be a problem here. Since the intention is only to remove one form then screwing up the further 'FOR EACH' processing shouldn't matter - especially if the FOR EACH loop was exited from within the IF..ENDIF ?

>And also, as Boris said, you probably need to check name of the form, not caption.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform