Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Create Single COMMON class that exists in 10 classes
Message
De
17/02/2009 11:53:15
 
 
À
17/02/2009 11:08:11
Information générale
Forum:
Visual FoxPro
Catégorie:
Classes - VCX
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows XP SP2
Network:
Windows XP
Divers
Thread ID:
01382376
Message ID:
01382398
Vues:
91
>Hi all
>
>- I have to create a single class COMMON
>- Single one instance of this class should be exist in 10 other classes
>
>Example
>
>
>
>oCommon = createobject("common") && This is declared somewhere in my application
>
>** class creation
>oClass1 = createobject("class_1")
>oClass2 = createobject("class_2")
>oClass3 = createobject("class_3")
>oClass4 = createobject("class_4")
>
>** I want to Add oCommon to oClass1-6 where if I write something like
>oClass1.oCommon.Prop_1 = 10 && Assign a value to a property in oClass1 will affect all the other classes
>
>? oClass2.oCommon.Prop_1 && <-- Gives 10
>? oClass3.oCommon.Prop_1 && <-- Gives 10
>? oClass4.oCommon.Prop_1 && <-- Gives 10
>
>
>
>What is the best way of doing this especially if oCommon = createobject("common") will be executed only once?
>
>TIA

Try this...
oCommon = createobject("common") && This is declared somewhere in my application

** class creation
oClass1 = createobject("class_1")
oClass1.AddProperty("Common",oCommon)
oClass2 = createobject("class_2")
oClass2.AddProperty("Common",oCommon)
oClass3 = createobject("class_3")
oClass3.AddProperty("Common",oCommon)
oClass4 = createobject("class_4")
oClass4.AddProperty("Common",oCommon)

** I want to Add oCommon to oClass1-6 where if I write something like
oClass1.oCommon.Prop_1 = 10 && Assign a value to a property in oClass1 will affect all the other classes

? oClass2.oCommon.Prop_1 && <-- Gives 10
? oClass3.oCommon.Prop_1 && <-- Gives 10
? oClass4.oCommon.Prop_1 && <-- Gives 10
Because all the child object share the same instance of Common as oCommon. Assign a value to one should appear in all.

Beside all this, why are you do this. Why not just use oCommon when ever you need to reference one of its properties?
Greg Reichert
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform