HELP:Accessing a class object in another class!

HELP:Accessing a class object in another class!

Post by Kouroche Sedaghatia » Thu, 05 Feb 1998 04:00:00



This is a little diffficult to explain, but I'll try.

I have three classes:
A (object)
B (collection of A)
C (contains a B object, an A object and another object we'll call objD)

now when I do something like C.B.Add (parameters) in my main form, I will be
adding a new A object to the B collection of class C, but at the same time I
want to manipulate objD.

Object A has similar properties to objD and I'd like keep them syncronized.
Everytime a property of an A object is changed, I'd like to change the
property of the corresponding objD as well.

My question is how can I have access to objD in class module B?
Is there a way to overwrite the add method of B in class C?

The only way I could manage was by creating events in B and then
manupulating objD in class C when B events occur.  Is there another way?

I know this sounds ambigious but if you have any ideas please let me know.

Kouroche

 
 
 

HELP:Accessing a class object in another class!

Post by Andre' Somer » Thu, 05 Feb 1998 04:00:00



>This is a little diffficult to explain, but I'll try.

>I have three classes:
>A (object)
>B (collection of A)
>C (contains a B object, an A object and another object we'll call objD)

>now when I do something like C.B.Add (parameters) in my main form, I will
be
>adding a new A object to the B collection of class C, but at the same time
I
>want to manipulate objD.

>Object A has similar properties to objD and I'd like keep them syncronized.
>Everytime a property of an A object is changed, I'd like to change the
>property of the corresponding objD as well.

>My question is how can I have access to objD in class module B?
>Is there a way to overwrite the add method of B in class C?

>The only way I could manage was by creating events in B and then
>manupulating objD in class C when B events occur.  Is there another way?

>I know this sounds ambigious but if you have any ideas please let me know.

>Kouroche

You could use Parent properties. Create a Public Object-type variable called
Parent in each class. When you create an instance of the class (an object),
you set it's Parent property to the object you are creating the class in.
Say you are creating a new instance of object A in your collection B. You
can have your AddItem method set a reference to object B in object A like
this, assuming the AddItem is a method of B:

Set A.Parent = Me

You can now access the properties and the methods of B from A, by using the
Parent. If you give object B a Parent property too, and make it a reference
to object C, you can access the properties of C from both B and A. Because
you can access object D from object C, you can use a syntax like this to
access a property in object D from an object A:

Parent.Parent.DObject.MyProperty="Created from A".

If you would like to synchronize object D with some object A, I would create
a method in object C wich can do this. It would take a reference to an
object A-type object, so the syntax would be (from within object A):

Parent.Parent.SynchronizeDObject Me

If object A and object D are realy the same type of objects, why not just
have a reference to object A itsef?

I hope this helps. If anyone got better ideas, please post them and CC to:

Andre'

 
 
 

1. I am not able to see my database class members in class view - Please help

Hi All,

I created a recordset class using ODBC link. After creating the class if I
view it in the class view there are no class members at all. I expected the
filed names to be present as class members. Sometimes when I create new
class it is showing up but sometimes it is not showing up. Any suggestions
please?

Thanks
Anand

2. How to show *.bmp on a generated report?

3. VB SQL server database access object/class?

4. SELECT problem

5. can't delete Microsoft Access Class Objects

6. mathprof's app

7. VB SQL server database access object/class?

8. Calculating Free Times using SQL

9. Visual class object access from .PRG

10. HELP! classes and objects

11. Class/Object help....

12. Visual C++ ADO- linking to wrapper classes gives link errror but not raw classes

13. Parameters, Classing and Sub-Classing