Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Andy Kramek
  Where is Andy Kramek?
 Hot Springs Village
 Arkansas - United States
 Andy Kramek
 To: Doro Galla
  Where is Doro Galla?
 Pennsylvania - United States
 Doro Galla
Subject: RE: vartype() and pemstatus() problems
Thread ID: 78497 Message ID: 78521 # Views: 1 # Ratings: 0
Version: Visual FoxPro 8 Category: Errors & Debugging
Date: Tuesday, October 04, 2005 8:51:54 PM         

Hi Doro
> I have written custom error handler that’s in my form. And I have written a small routine to test in the object like a button to see if it’s available. If object is on the form it works fine.
> But when I added those tests in a custom class library the test fails.
> This is how I test for it in my custom class lib:
> IF pemstatus(THISFORM, 'handle_error', 5)
> * if there's form level EH use it
> THISFORM.handle_error(nError, cMethod, nLine)
> In the debugger it finds that VARTYPE(thisform) expression cannot be evaluated. I expected this yet execution goes to the pemstatus() test and thisform cannot be evaluated either.
> Why did vartype() … allow this, if thisform is an object at this point why did pemstatus() fail?

VARTYPE() only does a single pass evaluation, unlike TYPE() which does a two-pass evaluation of the reference. In other words if "ThisForm" does NOT exist, VARTYPE will throw an error (and in the debugger it will pass to the next line, as Paul pointed out). You should, therefore, use TYPE() in this case because VFP will first check to see if the refernce exists, if not, it will return "U" and if it does it will then try and evaluate it.

The snag, of course, with TYPE() is that if the reference ever was an object it will return "O" - even if it no longer exsts. Therefore the only safe way to do this is to use:
IF TYPE( thisform ) = "O" AND NOT ISNULL( thisform )

That will correctly handle all scenarios.

Andy Kramek
Microsoft MVP (Visual FoxPro)
Tightline Computers Inc, Akron Ohio, USA


vartype() and pemstatus() problems Posted by Doro Galla @ 10/4/2005 3:26:33 PM
RE: vartype() and pemstatus() problems Posted by Paul Brown @ 10/4/2005 3:31:09 PM
RE: vartype() and pemstatus() problems Posted by Andy Kramek @ 10/4/2005 8:51:54 PM
RE: vartype() and pemstatus() problems Posted by Doro Galla @ 10/5/2005 3:07:24 PM