Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VFP 7.0 How to know if a form is open 1

Status
Not open for further replies.

bettyfurr

Technical User
Mar 12, 2002
371
US
I need to know if I have opened this form. If it is open I want to enable some objects. If the "ofnc" is open, the program does what it suppose to do when I enable these objects, if not open, the system crashes. I have tried an IF statement to determine, open or not with no avail. What dumb thing am I doing?

I use

do form fnc name ofnc

when I open the form

I have tried "if ofnc.FORM" and this bombs with the error not an object.

I have tried "if ofnc" this works OK if the form is open; same as above if not.

Please help

Betty :-(
 
Code:
if type("ofnc") = "O"
  ... the form is open
else
  ... the form is not open
endif

Regards

Griff
Keep [Smile]ing
 
Hello Griff,


Public ofnc

I have it public and have not intialized its type. It is showing logical. When I did not have it public, I was maintaining the "Name" ofnc when I opened another form (I had not closed ofnc)

What was happening here?

Betty

By the way, the keep smiling icon made me smile. thank you.
 
Hi Betty,

You don't really need the public variable for ofnc

If you declare a public (or private, or local) variable like this VFP will assign it a type of logical to be getting on with (and make it false BTW) - VFP variables are similar to VB's variant type and the type changes to match the data stored in it.

When you execute the do form ... name ofnc VFP will assign the form to the ofnc variable (it will become of type object).

If you then open another form, without closing the first, using the same ofnc name clause, VFP will assign the new form to your ofnc variable - and you will loose the ability to access the original form. Even it's underlying name will be lost.

Does that help?



Regards

Griff
Keep [Smile]ing
 
I know what you are saying about the logical variable. Are there anyway to set the variable to an object variable?

I only open that one form, fnc, using the ofnc name.

Yes, all your suggestions help!

I use this statement in another form on unload,
ofnc.setall

if the do form fnc name ofnc has not occurred I get an error. I think you have solved my problem with the type statement. I will try this tonight and let you know.

thank you.

Betty

 
Hi Betty

"Are there anyway to set the variable to an object variable?"

The public variable will adopt the type of it's content - if you follow me - unlike VB where you would specify the type at the declaration stage (typically).
VB:
Code:
Dim ofnc as form

You need not necessarily specify a name for the form at the time you open it either - I very rarely do. The form will have a name of it's own you can generally use (in your case 'fnc') and if you test for the 'type' of fnc it will return either O or U if it is open or not (respectively).

So, in the unload method of the other form you might do:
Code:
if Type("fnc") = "O"
  fnc.caption = "whoppee"
endif

This would work where you opened fnc like this:
Code:
do form fnc

Clearly, if you need two instances of fnc open at the same time, you will need to use the name clause.


BTW:

I always try to apply the 'C' language principles to variables and think of them as pigeon holes that contain references (or pointers) to actual data - so when you open a form with the name clause, that name becomes a 'pointer to an object of type form' and if you assign a number to it, then it will become a 'pointer to an object of type numeric'


Regards

Griff
Keep [Smile]ing
 
Thank you,

I will try this tonight.

Looks good!

betty :)
 
To try to save you some frustration, the variable retains its type after it gets set to null:
Code:
messagebox( TYPE("ofnc") ) && displays "U"
messagebox( VARTYPE(ofnc) ) && Throws Error (ofnc doesn't exist)
public ofnc
messagebox( VARTYPE(ofnc) ) && displays "L"
do form fnc name ofnc 
messagebox( TYPE("ofnc") ) && displays "O"
messagebox( TYPE("ofnc.caption") ) && displays "C"
messagebox( VARTYPE(ofnc) ) && displays "O"
ofnc.release
messagebox( TYPE("ofnc") ) && still displays "O"
messagebox( ofnc ) && displays ".NULL."
messagebox( TYPE("ofnc.caption") ) && displays "U"
messagebox( isnull(ofnc) ) && displays ".T."
messagebox( VARTYPE(ofnc) ) && displays "X"

So, if you follow the progression above, you should check Both the type using TYPE() and ISNULL, or use TYPE to check a property type (like TYPE("ofnc.caption")), or use VARTYPE which will return "X" when the form goes .NULL.

- Bill

Get the best answers to your questions -- See FAQ481-4875.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top