Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
VFP COM Design Problem
Message
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Miscellaneous
Thread ID:
01214563
Message ID:
01214634
Views:
9
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,
Previous
Reply
Map
View

Click here to load this message in the networking platform