Then you can always use Code Access Security.
oh wait this is VFP :-) J/k
Now serious then you don't have that many of a choice and looks like in that case the use of a public var is the easy one to have.
>I should have mentioned that I want it to be OLEPUBLIC, as I want it to appear
>in the object browser.
>
>It is necessary for users to be able to view the properties and methods on the
>child class. I just want to prevent them from instantiating it from outside
>the main class.
>
>
>
>>Kevin REmove the OLEPUBLIC keyword from your DEFINE CLASS stament for the class you don't want to be instantiated from the outside world, only classes mark as OLEPUBLIC are allowed to be created by an outside application.
>>
>>>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.
>>>
>>>One solution that I came up with is this:
>>>
>>>
>>>
>>>** Main Class
>>>PROCEDURE GetChildClass() AS Object
>>>
>>> LOCAL oRetVal AS Object
>>>
>>> PUBLIC gb_AllowChildClass
>>>
>>> oRetVal = This.GetChildClass()
>>>
>>>ENDPROC
>>>
>>>
>>>And in the Child class's Init:
>>>
>>>PROCEDURE Init()
>>>
>>> LOCAL bRetVal AS Boolean
>>> bRetVal = .T.
>>>
>>> IF TYPE("AllowChildClass") = "U"
>>> bRetVal = .F.
>>> ENDIF
>>>
>>> RETURN bRetVal
>>>
>>>ENDPROC
>>>
>>>
>>>Since the whole thing is in a DLL, it's in its own session, so there should
>>>be no issue with using a public variable.
>>>
>>>Still, I don't really feel good about it.
>>>
>>>Anyone have a better way?
Alexandre Palma
Senior Application Architect