>Hi,
>
>The title of this thread is the error message I get in this situation.
>
>I have a form and a class is dropped on this form. E.g. class MyClass1. It is instantiated with any problem.
>
>In the INIT of this form another class is instantiated as follows
>
>
>thisform.oMyClass2 = NEWOBJECT( "MyClass2", "MyClass2Lib.VCX")
>
>
>When when I want to get/reference a property of the MyClass1 in a method of MyClass2, I get error "Object is not contained in a form." The way I reference class MyClass1 in a method of MyClass2 is as follows:
>
>
>thisform.MyClass1.aProperty
>
>
>I thought that since MyClass2 is in the same form that instantiated the MyClass1 I would be able to reference it, but apparently I am wrong. What am I missing?
The problem you are facing is actually a dependency problem. in this design you should be careful about what your class should "Know" about the form. If you create the wrong dependencies all your classes will be useless in another context, they cannot be plugged into other places. I believe you should move the logic to the form, which is supposed to handle as a controller in this situation.
thisform.oMyClass2 = NEWOBJECT( "MyClass2", "MyClass2Lib.VCX")
BINDEVENT(thisform.oMyClass2,"YourmethodInClass",THISFORM,"OnMethodInClass")
In the class that you dropped on the form you create that event:
MyClass2.YourmethodInclass()
and on the form you create the method:
THISFORM.OnMethodInClass()
The method can look like this:
AEVENTS(la,0)
loCallingClass = la[1]
THISFORM.MyClass1.aProperty = loCallingClass.AnotherProperty
Christian Isberner
Software Consultant