Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Dealing with dangling reference
Message
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Versions des environnements
Visual FoxPro:
VFP 9 SP1
Divers
Thread ID:
01539074
Message ID:
01539076
Vues:
45
>>Hi,
>>
>>I believe I understand my problem with dangling reference and looking for a suggestion on resolving it. Here is the summary of the problem.
>>
>>I have a form A that get a cursor from database and shows the information to user. This form has a button (Browse) that when user clicks on opens another form (call it form B) that shows the same information in the grid format. Keep in mind that form B uses the cursor created in form A (so when I close form A I need to close form B). When I close form A I close/release form B (either in QueryUnload or Unload method) and everything works fine. The problem is if both form A and form B are open and a user clicks on the X in the upper right corner of the application (indicating that he/she wants to close the application).
>>
>>The program then calls a routine (Cleanup()) that closes all open forms. This routine starts with
>>
>>for each oForm in Application.Forms
>>
>>What happens then is this routine closes form A (which is at the top of the Application.Forms collection) and form A closes form B. But the Applications.Forms collection still holds a reference to the form B. So when it tries to "deal" this this reference, the program crashes. That is, the variable oForm initialized in the above line is dangling and any attempt to evaluate this, causes a crash.
>>
>>What would you suggest? TIA.
>
>You can not use FOR EACH oForm loop
>if you're closing the forms (removing from the collection). You need to use FOR loop starting from the last form. Please check again the FAQ.

Sorry I didn't notice this difference. Thank you for pointing it. I am going to review the FAQ again.
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform