Microsoft KB Archive/255725: Difference between revisions

From BetaArchive Wiki
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 = &quot;This is a test.&quot;
     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 = &quot;This is my name&quot;
   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(&quot;mytest.myole&quot;) &&Loads the myole class of mytest.dll
<pre class="codesample">oMyObj = CREATEOBJECT("mytest.myole") &&Loads the myole class of mytest.dll


?oMyObj.GiveReturn() &&This will print &quot;This is a test.&quot; to the screen
?oMyObj.GiveReturn() &&This will print "This is a test." to the screen


oMyObj.ADDOBJECT(&quot;oMyName&quot;,&quot;myclass&quot;) &&Add newclass object to myole
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 &quot;This is my name&quot; to the screen
<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

Knowledge Base


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:

OLE error code 0x80020006: Unknown name

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:

  1. Within Microsoft Visual FoxPro 6.0, create a new project called mytest.
  2. 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
                        
  3. Close and save the program as test.
  4. 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.
  5. 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
                        
  6. 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