Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Preventing multiple instances of a form
Message
From
27/01/1997 10:56:18
Paul Wei
Fib, State of Michigan
Lansing, Michigan, United States
 
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00018445
Message ID:
00018471
Views:
38
>>>Does anyone have a way of preventing multiple instances of a form without setting the Form WindowType property to 1-Modal?
>>
>>Use the code similar to:
>>
>>If type('oMyForm') # 'O' or isnull(oMyForm)
>> oMyForm = creatobject('MyForm')
>>endif
>>
>>
>>Well anything like that should work.
>>
>>Tom
>
>
> I am not calling the forms as classes. I am using DO FORM. Is their something I could put in the Init method?

Tom's code is for an object but will work with a form as will if you associate the form with an object memory variable by using the "name" option with the "do form" command:
   If type('oMyForm') # 'O' or isnull(oMyForm)
     public oMyForm
     do form MyForm name oMyForm 
   else
     oMyForm.show() &&move the first instance of MyForm to the forefront
   endif

It's important to make oMyForm public so it won't go out of scope.  Also, you may want to release the object variable oMyForm in the Release method of MyForm.

If you want to do this check inside of the form's own Init method, you can  do the reverse of the above "If" statement in Init method and return a false value to stop the creation of the form, something like:

   public oMyForm
   do form MyForm name oMyForm
   .
   .

   * MyForm's Init method
   if type('oMyForm')='O' and !isnull(oMyForm)
     return .F.
   endif
   * the rest of Init method
   .
   .
Again, make sure you declare oMyForm a public variable first. But all things considered, I think it's a better idea to do this check outside of the form.

Paul
Previous
Reply
Map
View

Click here to load this message in the networking platform