View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Michel S. Michel S. is offline
external usenet poster
 
Posts: 33
Default Problem using an object inside another object..

Hello !

In a form module, I create an instance of a class object and I
initialize this object.

Set obj01 = New clsObj01

Later in the same procedure I create some instances of another class,
Set obj0201 = New clsObj02
Set obj0202 = New clsObj02
Set obj0203 = New clsObj02

All these objects are created in the UserForm_Initialise procedure and
destroyed in the UserForm_Terminate proc.

They are also defined as global at the form module level
Private obj01 AS clsObj01
Private obj0201 AS clsObj02
Private obj0202 AS clsObj02
Private obj0203 AS clsObj02


Always in the UserForm_Initialize procedure, I set one of this second
class properties to the first object in all instances :

Set obj0201.obj = obj01
Set obj0202.obj = obj01
Set obj0203.obj = obj01


This second class has the correct Property Set procedure :

Public Property Set ExtObject (obj AS clsObj01)
Set mobj = obj
End Property

of course, mobj is defined global at module level :
Private mobj AS clsObj01


Tracing the code in the property Set procedure, I can query the
properties of mobj and the correct values are returned.


In the clsObj02 module, there's another method I call later that uses
one of the properties of mobj

Public Sub ...

If mobj.Complete = True Then ...

I get an error 91 on that line (undefined object variable), and the
local variables window shows that mobj is nothing.

Since obj01 still exists (the form is still displayed and it's
Terminate procedure never executed at that point), I don't understand
why this happens..

Any idea ?
Thanks

NB: I also tried to use "Private mobj AS *New* clsObj01" in clsObj02,
but it doesn't make any difference, and IMHO it is not required because
it is not a new object, but a reference to an existing object.