Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Prevent opening a form if it's already opened.
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Gestionnaire d'écran & Écrans
Divers
Thread ID:
00557131
Message ID:
00558614
Vues:
24
Hi!

Sorry, forget that _Screen.Forms collection already updated by that form in the form Load method. The condition should be following:
     if _Screen.Forms(i).Name == this.Name AND _Screen.Forms(i)<>this
Note that object references are compared correctly in VFP.

HTH.


>Vlad,
>
>I am very confused. If you saw my other reply to you, you know my problem is that I just get a flash of the form when your suggested code is in the LOAD event of the Class OR the Form. I think the problem is in the third line of code that says
>
>
>     if _Screen.Forms(i).Name == this.Name
>
>
>This line returns a True condition even though this is the first instance of the form. Looking in the _Screen.Forms() Collection in Debugger just before the first line of LOAD event fires, I can see that the form exists with the same name as the one I am creating.
>
>What's the deal? I don't understand.
>
>>Hi!
>>
>>First of all, do not use the variable created with name that match to form name. This variable is usable only in design-time mode for debugging purposes to quickly view the properties and objects of the form. In run-time mode this variable is nto reliable for referencing forms, do not use it in the code in the future.
>>
>>You can use the _Screen.Forms collection to check if some particular form is opened:
>>
>>* form class load event
>>if this.lOnlyOneInstanse && custom flag property, set it to .T. if form could be opned only once
>>  for i=1 to _Screen.FormCount && loop through all opened forms
>>    if _Screen.Forms(i).Name == this.Name && check if this form name match to any opened form name
>>      nodefault && prevent this form from loading
>>      _Screen.Forms(i).Show() && show the instanse of the form with this name that is already opened
>>      return .F. && do not continue any more in this instanse of the object
>>    endif
>>  endfor
>>endif
>>
>>
>>HTH.
>>
>>>I know there has to be a standard way to do this. Within my app I launch forms from menus, from command buttons within other forms, and by double-clicking areas of forms, all using the DO FORM command. I am using the following code in the LOAD event of some of my forms to prevent creating a new instance of the form if it already exists:
>>>
>>>IF TYPE("Reportselect") = "O" and !ISNULL(Reportselect)
>>> Reportselect.Show()
>>> RETURN .F.
>>>ENDIF
>>>
>>>Of course "Reportselect" is the name of this particular form. How can I use a generic version of this code in the base class for my forms.
>>>
>>>
>>>Thank you kindly for your help.
Vlad Grynchyshyn, Project Manager, MCP
vgryn@yahoo.com
ICQ #10709245
The professional level of programmer could be determined by level of stupidity of his/her bugs

It is not appropriate to say that question is "foolish". There could be only foolish answers. Everybody passed period of time when knows nothing about something.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform