>Hi Antonio,
>
>If I may ask you a follow up question, please.
>
>The class that I am creating, by subclassing, will be used in a Form. And the custom method that will have "my" code will have a reference to the form (e.g. thisform.) Which causes the error.
>How do I use this subclassed object in the Form so that the custom method would be able to reference the Thisform?
>
>UPDATE: I think I need to instantiate the class in the INIT of this method using NewObject().
Dmitry
For an object - of any class - to be able to address the form using the Thisform reference, it must be part of the form (that is, it must be contained by the form). If you try to instantiate it during Init, it won't be a form object unless you add it to the form (AddObject() instead of NewObject()).
You may try the different results by changing the values of the #DEFINEs at the beginning.
#DEFINE AS_A_FORM_OBJECT .T.
#DEFINE ADD_AT_INIT .F.
LOCAL Test AS DF
m.Test = CREATEOBJECT("DF")
m.Test.Show(1)
DEFINE CLASS DF AS Form
ADD OBJECT ClickMe AS CommandButton WITH Caption = "Click me!"
#IF AS_A_FORM_OBJECT
#IF !ADD_AT_INIT
ADD OBJECT SaySomething AS X
#ELSE
FUNCTION Init
This.AddObject("SaySomething", "X")
ENDFUNC
#ENDIF
#ELSE
SaySomething = .NULL.
FUNCTION Init
This.SaySomething = NEWOBJECT("X")
ENDFUNC
#ENDIF
FUNCTION ClickMe.Click
Thisform.SaySomething.MethodOne()
ENDFUNC
ENDDEFINE
DEFINE CLASS X AS Custom
FUNCTION MethodOne
Thisform.Caption = "Hola @ " + TTOC(DATETIME(), 2)
ENDFUNC
ENDDEFINE
Of course, one could argue if your subclass shouldn't be looking for a form in its class hierarchy, and only issue Thisform when it found one.
----------------------------------
António Tavares Lopes