Click to See Complete Forum and Search --> : If you've got CLASS, answer this!
Aaron Young
Jan 6th, 2000, 02:20 AM
I'm not sure I follow you completely, but have you tried using Me, ie.
In the Classes Init Event:
Set OwnObjectReference = Me
I don't follow your need for a reference to itself, as you can always just use Me, it makes more sense to have a Reference to a Parent Object, i.e when you create O2, in O1:
Set O2 = New clsObject2
Set O2.CreatingObjectReference = Me
------------------
Aaron Young
Analyst Programmer
aarony@redwingsoftware.com
ajyoung@pressenter.com
LG
Jan 6th, 2000, 05:40 AM
Why cannot you create a Class2 inside Class1
Then at the time of creation of Class1 you will automaticaly cteate a Class2 object and can access it thrue Class1 property or methods.
I would go that way
LG
How does a class get an object reference to Itself? Case in point:
Main program creates Class1(c1)
C1 needs to create its own class to do its job, so It creates Class2(C2).
C1 does not want to wait for C2 to complete, (Run asyncronously) but wants to return control immediately to the main program.
When C2 has completed, it needs to notify C1 that it is done.
I have seen examples where an event is raised, but this seems kind of kludgy. I have implemented this type of structure passing object references along, and it seems to work Ok, however I don't know how to get the object refence in the class itself. Currently I must set it as a property when the object is created. For example:
MainLIne:
Set O1 = new clsObject1
set O1.OwnObjectReference = O1
(at this point, O1 has a refence to itself (which we will call pOwnObjectReference) which it can pass to O2 when it is created.
O1.Execute
This starts O1 working. O1 now does the following:
set O2 = new clsObject2
set O2.OwnObjectReference = O2
Set O2.CreatingObjectReference = pOwnObjectReference
O2.Execute
At this point O2 has an object reference to itself(which it can pass to any objects it creates, and it has a reference to the object (called pCreatingObjectReference) which created it(O1). When it has finished processing, it can notify O1, by performing a function of O1 (called "Finished") by using the O1 object reference:
pCreatingObjectreference.Finished
This seems to work Ok, however it breaks the rules for object programming (encapsalation) as each object is depending on its creator to initialize one of its required fields (the object reference to itself). It would be much cleaner if the object itself could get its own object reference.
Does anyone know how to do this? Is there a better way to do this? I'm open to suggestions.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.