>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:
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.