Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
VARTYPE vs TYPE with Parent property
Message
De
25/07/2002 03:50:47
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
24/07/2002 15:52:33
Beth Wetherbee
Virginia Beach Public Schools
Virginia Beach, Virginie, États-Unis
Information générale
Forum:
Visual FoxPro
Catégorie:
Classes - VCX
Divers
Thread ID:
00682266
Message ID:
00682415
Vues:
24
>I have discovered some curious behavior and I'm wondering if someone can explain it to me.
>
>I have a simple class called 'TableCreator' based on the Session class. In its Error event, I want to pass the error up to the parent of the object, if there is one, otherwise just do the default error behavior. So, in the Error event I put this code:
>
>debug && so I can watch it work
>susp
>IF VARTYPE(This.Parent) = 'O'
> This.Parent.Error(nError, cMethod, nLine)
>ELSE
> DODEFAULT(nError, cMethod, nLine)
>ENDIF
>
>To test it, I instantiated the object in the command window,:
>ox = NEWOBJECT('TableCreator', 'CreateTables.prg')
>
>then fired the error event:
>ox.Error(1)
>
>As I was stepping through the code, I expected IF VARTYPE(This.Parent) = 'O' to fail, because the object has no parent. In the debug watch window, VARTYPE(This.Parent) returns 'Expression cannot be evaluated'. But, IF VARTYPE(This.Parent) = 'O' passed, so it hit the This.Parent.Error line!
>
>In the command window:
>?TYPE('ox.parent') && returns 'U'
>?VARTYPE(ox.Parent) && blows error - 'Parent is not an object'
>
>Well, I know it's not an object, so why doesn't ?VARTYPE(ox.Parent) return a 'U'? And more importantly, why does IF VARTYPE(ox.Parent) = 'O' pass when Parent is not an object?
>
>I changed the code to
>IF TYPE('This.Parent') = 'O'
>and it worked as expected - returns a 'U', so that IF fails.
>
>I also tried this:
>loParent = This.Parent
>IF VARTYPE(loParent) = 'O'
>That worked too! VARTYPE(loParent) returned 'U', so the IF failed.
>
>I'm in VFP 7.0.
>
>To make sure it wasn't just a 'session' class thing, in the command window, I typed:
>ox = NEWOBJECT('form')
>
>?VARTYPE(ox.Parent) && blows the 'Parent does not exist' error
>?TYPE('ox.Parent') && returns 'U'
>
>Can anyone shed some light on this for me?
>
>TIA,

Beth,
From my POV it's a bug in VFP6 and VFP7. Despite its slowness I stick to type for its consistent results.
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform