Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
VFP COM Design Problem
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
COM/DCOM et OLE Automation
Divers
Thread ID:
01214563
Message ID:
01214634
Vues:
10
Hi, Kevin.

>I have PRG-based classlib that will be compiled into a DLL. There are classes in
>the DLL that I only want instantiated through methods in the main class.
>
>The problem is how to prevent a class from being instantiaed from outside the
>main class.

Public variables??? Oh, no!!! 8-)

Why about a bit of stack trace walking?
Clear
dad = NewObject("ParentClass")

son1 = NewObject("ChildClass")  && You can't !!
? son1

son2 = dad.GetChildClass()		&& Well, this is happier
? son2


Define Class ParentClass As Session

   Procedure GetChildClass() As Object
      Return NewObject("ChildClass")
Enddefine

Define Class ChildClass As Session

   Procedure Init()
      Return Program( Program(-1) -1) = Upper("ParentClass.GetChildClass")

Enddefine
I don't like so much coupling, but I prefer this to global vars, anyway.

Hope this helps,
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform