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:
01214644
Views:
8
Kevin,

I am not sure I understand the requirements, anyways, maybe you can use an interface instead?

For example:
* Project: TestPrivateClassInterface
* Program: myTestInterface

define class myTestInterface as Session olepublic
	function Test() as Boolean
	endfunc
	
	function AnotherTest() as Boolean
	endfunc
enddefine
* Project: TestPrivateClass
* Program: myMainTest

define class myMainClass as Session OLEPUBLIC
	protected myObject as Object
	
	function getMyObject() as Object
		return this.myObject
	endfunc
	
	function init() as Boolean
		this.myObject			= Createobject('myTestClass')
	endfunc
enddefine

* Now define your child class without OLEPUBLIC
define class myTestClass as Session
	IMPLEMENTS Imytestinterface IN "testprivateclassinterface.myTestInterface"

	PROCEDURE Imytestinterface_Test() AS LOGICAL
		return .t.
	ENDPROC

	PROCEDURE Imytestinterface_AnotherTest() AS LOGICAL
		return .f.
	ENDPROC
enddefine
[Update] Silly me... I opened the wrong DLL that is why I saw those methods, Now I see my wrong ways, the intellisense part is right thou[/update]

Now, in the ObjectBrowser you'll see Test and AnotherTest and you even have intellisense if you do something like:
loTest		= Createobject('TestPrivateClass.myMainClass')
loMyTestObject	= Getinterface(loTest.getMyObject(), 'ImyTestInterface', 'TestPrivateClassInterface.DLL')
now intellisense will show
loMyTestObject.
               AnotherTest
               Test
>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 && This must exist in the child class Init
>>>
>>>  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?
"The five senses obstruct or deform the apprehension of reality."
Jorge L. Borges?

"Premature optimization is the root of all evil in programming."
Donald Knuth, repeating C. A. R. Hoare

"To die for a religion is easier than to live it absolutely"
Jorge L. Borges
Previous
Reply
Map
View

Click here to load this message in the networking platform