Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to detect if a form is already open?
Message
From
04/12/2005 16:48:21
Dragan Nedeljkovich (Online)
Now officially retired
Zrenjanin, Serbia
 
 
To
04/12/2005 14:01:07
John Faithfull
Hunterian Museum, University of Glasgow,
Glasgow, United Kingdom
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Environment versions
Visual FoxPro:
VFP 9
OS:
Windows 2000 SP4
Network:
Novell 5.x
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01074732
Message ID:
01074784
Views:
22
>Hi Michel,
>
>Sorry for lack of clarity. This is the code:
>
>
>if wexist("hugform")=.T.
>       hugform.release()
>endif
>
>
>gives the error
>
>1923 object HUGFORM is not found
>
>wexist("hugform") does evaluate to .T., but the object can't be referenced.
>
>Although wexist() treats a form as being a Window, "deactivate window" doesn't seem to work for closing forms.

Wexist() checks for a window whose window name is the parameter. So if you had a form First.scx, instantiated with

do form First name oSecond

and then had

oSecond.name="third"

Wexist("third") would be true, but the variable holding the reference to the object would still be oSecond. So we have three names here - the scx name (can be anything, it's just a filename), the variable name (that you assign with a Name clause of Do Form, or one gets created behind the scenes, but you don't exactly know what it is), and the object's .name property, which is initially equal to its class name (with 1 appended to it), but you can assign it to be any valid (no spaces, can't start with a digit) name.

If you don't want to write your own forms handler, you can use _screen.Forms collection and iterate through it:
*-- function GetMyForm(cMyProperty, tMyPropertyValue)
lParameters tMyPropertyValue
for each oForm in _screen.Forms
if getpem(oForm, cMyProperty)=tMyPropertyValue
   return oForm
   exit
endif
endfor
return null
Now it's up to you to have some nice property that would let you know whether your form is already up. Let it be the caption:
oFrm=GetMyForm("caption", "InTwoVoices")
if isnull(oFrm)
   do form In2Voices name oInvoices2
else
   oInvoices2=oFrm
   oFrm.show()
endif
This code may even work with a little tweaking. It's easier if you don't use scxes, but build your forms as classes - then your best candidate property is the classname.
I haven't tested this, but I've written similar code a dozen times.

back to same old

the first online autobiography, unfinished by design
What, me reckless? I'm full of recks!
Balkans, eh? Count them.
Previous
Reply
Map
View

Click here to load this message in the networking platform