Microsoft KB Archive/255725: Difference between revisions
m (Text replacement - "&" to "&") |
m (Text replacement - """ to """) |
||
Line 84: | Line 84: | ||
<li><p>Add a new program to the <span class="kbd userinput"> mytest</span> project and input the following code:</p> | <li><p>Add a new program to the <span class="kbd userinput"> mytest</span> project and input the following code:</p> | ||
<pre class="codesample">DEFINE CLASS myole AS CUSTOM OLEPUBLIC | <pre class="codesample">DEFINE CLASS myole AS CUSTOM OLEPUBLIC | ||
lcReturnValue = | lcReturnValue = "This is a test." | ||
FUNCTION givereturn | FUNCTION givereturn | ||
RETURN This.lcReturnValue | RETURN This.lcReturnValue | ||
Line 94: | Line 94: | ||
DEFINE CLASS myclass AS CUSTOM OLEPUBLIC | DEFINE CLASS myclass AS CUSTOM OLEPUBLIC | ||
lcMyName = | lcMyName = "This is my name" | ||
ENDDEFINE | ENDDEFINE | ||
</pre></li> | </pre></li> | ||
Line 100: | Line 100: | ||
<li>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'''.</li> | <li>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'''.</li> | ||
<li><p>In the Microsoft Visual FoxPro '''Command''' window, run the following lines of code:</p> | <li><p>In the Microsoft Visual FoxPro '''Command''' window, run the following lines of code:</p> | ||
<pre class="codesample">oMyObj = CREATEOBJECT( | <pre class="codesample">oMyObj = CREATEOBJECT("mytest.myole") &&Loads the myole class of mytest.dll | ||
?oMyObj.GiveReturn() &&This will print | ?oMyObj.GiveReturn() &&This will print "This is a test." to the screen | ||
oMyObj.ADDOBJECT( | oMyObj.ADDOBJECT("oMyName","myclass") &&Add newclass object to myole | ||
?oMyObj.oMyName.lcMyName &&This will produce the error | ?oMyObj.oMyName.lcMyName &&This will produce the error | ||
</pre></li> | </pre></li> | ||
<li><p>Use the following line of code in the '''Command''' window and confirm that the oMyNameobject is scoped to the returnmyname procedure:</p> | <li><p>Use the following line of code in the '''Command''' window and confirm that the oMyNameobject is scoped to the returnmyname procedure:</p> | ||
<pre class="codesample">?oMyObj.ReturnMyName() &&This will print | <pre class="codesample">?oMyObj.ReturnMyName() &&This will print "This is my name" to the screen | ||
</pre></li></ol> | </pre></li></ol> | ||
Latest revision as of 13:53, 21 July 2020
Article ID: 255725
Article Last Modified on 3/8/2000
APPLIES TO
- Microsoft Visual FoxPro 6.0 Professional Edition
This article was previously published under Q255725
SYMPTOMS
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:
CAUSE
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.
RESOLUTION
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.
STATUS
This behavior is by design.
MORE INFORMATION
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