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 Wetherbee, MCSD
VBCPS