Microsoft KB Archive/255725
Article ID: 255725
Article Last Modified on 3/8/2000
- Microsoft Visual FoxPro 6.0 Professional Edition
This article was previously published under Q255725
If an object is added to a Component Object Model (COM) server at run time, attempts to access that object result in the following error message:
Visual FoxPro looks in the type library file (.tlb) to locate the object name reference associated with the COM server. When Visual FoxPro cannot find the object name reference there, it produces the error.
To resolve this situation, do one of the following:
Add a procedure or procedures to the COM server that can access the added object or objects.Utilize functions or procedures in lieu of adding objects to COM servers at run time.
This behavior is by design.
To produce the behavior, perform the following steps:
- Within Microsoft Visual FoxPro 6.0, create a new project called mytest.
Add a new program to the mytest project and input the following code:
DEFINE CLASS myole AS CUSTOM OLEPUBLIC lcReturnValue = "This is a test." FUNCTION givereturn RETURN This.lcReturnValue ENDFUNC PROCEDURE returnmyname RETURN This.oMyName.lcMyName ENDPROC ENDDEFINE DEFINE CLASS myclass AS CUSTOM OLEPUBLIC lcMyName = "This is my name" ENDDEFINE
- Close and save the program as test.
- In the Project Manager, click the Build button, and build a single-threaded COM server (DLL) in Visual FoxPro 6.0 with SP3, or build a COM DLL in Visual FoxPro 6.0. Upon completion of the build, close the Project Manager.
In the Microsoft Visual FoxPro Command window, run the following lines of code:
oMyObj = CREATEOBJECT("mytest.myole") &&Loads the myole class of mytest.dll ?oMyObj.GiveReturn() &&This will print "This is a test." to the screen oMyObj.ADDOBJECT("oMyName","myclass") &&Add newclass object to myole ?oMyObj.oMyName.lcMyName &&This will produce the error
Use the following line of code in the Command window and confirm that the oMyNameobject is scoped to the returnmyname procedure:
?oMyObj.ReturnMyName() &&This will print "This is my name" to the screen
Keywords: kbcodesnippet kbprb kbctrl KB255725