Microsoft KB Archive/324201

= PRB: Object Browser Generates Incorrect Interface Code =

Article ID: 324201

Article Last Modified on 7/23/2002

-

APPLIES TO


 * Microsoft Visual FoxPro 7.0 Professional Edition

-



This article was previously published under Q324201



SYMPTOMS
Microsoft Visual FoxPro 7.0 includes a new tool that is named the Object Browser. You can use the Object Browser to automatically generate class code when your class definition inherits the interface (class definition) of another Component Object Model (COM) component through the IMPLEMENTS statement. To do this, select a specific interface from the Classes and Members pane of the Object Browser, and then drag the interface into an empty program (.prg) file.

Depending on the class that is referenced, the code that the Object Browser generates when it performs this operation may be code for an interface other than the interface that you selected.



RESOLUTION
The source code for the Object Browser application is included with Visual FoxPro 7.0. The source code is included in a file that is named Xsource.zip. By default, Xsource.zip is installed in the Tools\Xsource subdirectory of the Visual FoxPro root directory.

To resolve this problem, you must extract, modify, and then rebuild the Object Browser application. To do this, follow these steps:

 Use WinZip, Windows Compressed Folders (in Microsoft Windows XP), or another archive reader that can read .zip files to extract the OBrowser directory from the Xsource.zip file. Right-click the OBrowser directory in Windows Explorer, click Properties, and then click to clear the Read-only check box. You can also use the attrib command to do this from a command prompt. Start Visual FoxPro, and then use the cd command to change the directory to the expanded OBrowser directory. Run the following command from the Visual FoxPro 7.0 Command window:

modify command patchobrowser

  Paste the following code into the program window that appears: *---
 * PatchOBrowser.prg
 * ABSTRACT: Updates the Visual FoxPro Object Browser application to
 * resolve problem that is outlined in Microsoft Knowledge Base *          article Q324201.
 * 1) DEFINE CR CHR(13) + CHR(10)
 * 1) DEFINE CR CHR(13) + CHR(10)

CD JUSTPATH(SYS(16)) IF !FILE(&quot;OBJECTBROWSER.PJX&quot;) MESSAGEBOX(&quot;The update .prg does not appear to be in the correct DIR.&quot; + CR + ;   &quot;See the Microsoft Knowledge Base article Q324201 for details.&quot; + CR + CR + ;    &quot;Exiting.&quot;,0,&quot;MSKB Q324201&quot;) RETURN .F. ENDIF
 * ~ Verify the correct location. If not, exit.

CLOSE DATABASES ALL RELEASE ALL CLEAR ALL

WAIT WINDOW &quot;Q324201 is patching the Object Browser. Please wait...&quot; NOWAIT NOCLEAR

LOCAL lcNewCode AS STRING, ; lcOriginalLoop1 AS STRING, ; lcOriginalLoop1 AS STRING, ; lcNewLoop1 AS STRING, ; lcNewLoop2 AS STRING

lcNewCode = &quot;&quot;

lcOriginalLoop1 = ; 'FOR i = 1 TO loTli.CoClasses.Count' + CR + ; '  IF loTli.CoClasses(m.i).DefaultInterface.Name = ALLTRIM(lcIntName)' + CR + ; '      lcProgID = loTli.Name + &quot;.&quot; + loTli.CoClasses(m.i).Name' + CR + ; '  ENDIF' + CR + ; 'ENDFOR'
 * First loop that needs replacing in objectbrowser::createinterfacecode

lcOriginalLoop2 = ; 'lnIntCount = loTli.Interfaces.Count' + CR + ; 'FOR i = 1 TO lnIntCount ' + CR + ; '  IF UPPER(loTli.Interfaces(m.i).Name) = UPPER(loNode.Text)' + CR + ; '      lnIntRef = m.i' + CR + ; '      EXIT' + CR + ; '  ENDIF' + CR + ; 'ENDFOR'
 * Second loop that needs replacing in objectbrowser::createinterfacecode

TEXT TO lcNewLoop1 NOSHOW TEXTMERGE LOCAL lcExact lcExact = Set(&quot;Exact&quot;) Set Exact On <> Set Exact &lcExact ENDTEXT
 * Update First loop
 * CODE INSERTED BY Microsoft Knowledge Base Article Q324201
 * CODE INSERTED BY Microsoft Knowledge Base Article Q324201

TEXT TO lcNewLoop2 NOSHOW TEXTMERGE LOCAL lcExact lcExact = Set(&quot;Exact&quot;) Set Exact On <> Set Exact &lcExact ENDTEXT
 * Update Second loop
 * CODE INSERTED BY MSKB Article Q324201
 * CODE INSERTED BY Microsoft Knowledge Base Article Q324201

USE objectbrowser.VCX IN 0 ALIAS &quot;LIB&quot; SELECT LIB GO TOP IF &quot;PATCHED BY Q324201&quot; $ UPPER(LIB.USER) WAIT CLEAR MESSAGEBOX(&quot;It appears OBJECTBROWSER.VCX has already been patched.&quot; + CR + ;       &quot;Expand a fresh copy of the Object Browser source before you try to patch it again.&quot; + CR + ;        &quot;See Microsoft Knowledge Base article Q324201 for details.&quot; + CR + CR + &quot;Exiting.&quot;,0,&quot;Microsoft Knowledge Base Q324201&quot;) RELEASE ALL CLOSE DATABASES ALL RETURN .F. ENDIF
 * ~ Open the ObjectBrowser class library as a table.
 * ~ See if this program previously patched the .vcx file.
 * ~ If so, exit.

LOCATE FOR (&quot;objectbrowser&quot; $ objname AND &quot;createinterfacecode&quot; $ methods) AND !DELETED
 * ~ Locate the correct record. The shipped version of this library had some deleted
 * ~ records that were not cleaned out, therefore, the DELETED clause in the LOCATE command.

lcNewCode = STRTRAN(LIB.methods, lcOriginalLoop1, lcNewLoop1) lcNewCode = STRTRAN(lcNewCode, lcOriginalLoop2, lcNewLoop2) REPLACE LIB.methods WITH lcNewCode
 * ~ Update the code, and then write the update back to the table.

GO TOP IN LIB REPLACE LIB.USER WITH LIB.USER + ; CR + CR + &quot;PATCHED BY Q324201 - &quot; + TRANSFORM(DATETIME) USE IN LIB
 * ~ Update the USER field of the first record to indicate that the the .vcx file has been patched.
 * ~ Read this at the start of THIS program to make sure that it is not patched
 * ~ more than one time.

COMPILE CLASSLIB objectbrowser.VCX
 * ~ Recompile the ClassLib to make sure that the changes take effect.

USE objectbrowser.PJX IN 0 ALIAS &quot;OBPJX&quot; SELECT OBPJX GO TOP REPLACE OBPJX.HOMEDIR WITH ADDBS(JUSTPATH(SYS(16))) + CHR(13) LOCATE FOR &quot;vssver.scc&quot; $ OBPJX.name IF !RECCOUNT(&quot;OBPJX&quot;) = RECNO(&quot;OBPJX&quot;) DELETE ENDIF USE IN OBPJX MODIFY PROJECT OBJECTBROWSER NOWAIT
 * ~ Rebuild ObjectBrowser.app
 * ~ A file that is named Vssver.scc is included in the project, but the
 * ~ physical file does not exist. This is a Microsoft Visual SourceSafe file
 * ~ and is not part of the Object Browser code. Manipulating the PJX as a table
 * ~ here removes the reference to prevent an error when the project opens and
 * ~ cannot find this file. The Home Directory project property is also updated.
 * ~ cannot find this file. The Home Directory project property is also updated.

RENAME HOME + &quot;OBJECTBROWSER.APP&quot; TO HOME +&quot;OBJECTBROWSER.APP.ORIGIONAL&quot; _VFP.ACTIVEPROJECT.BUILD(HOME + &quot;OBJECTBROWSER.APP&quot;,2,.T.,.T.) CLOSE ALL WAIT CLEAR MESSAGEBOX(&quot;Object Browser Updated!&quot;,0,&quot;Microsoft Knowledge Base Q324201&quot;)  Save the program, and then run the program:
 * ~ Rename the old (original) ObjectBrowser.app file, replace this file, and then cleanup.

NOTE: This program must be located in the OBrowser root directory to run correctly.</li></ol>

<div class="moreinformation_section">

Steps to Reproduce the Behavior
NOTE: You must install The Microsoft SOAP Toolkit before you follow these steps. The Microsoft SOAP Toolkit is included with the Visual FoxPro 7.0 CD. To download an updated version of the Microsoft SOAP Toolkit, visit the following Microsoft Web site:

Microsoft SOAP Toolkit

<ol> Start Visual FoxPro 7.0.</li> Clean up the Object Browser cache by deleting its working table. To do this, run the following command from the Visual FoxPro 7.0 Command window:

erase home + &quot;wizards\objectbrowser.*&quot; recycle

A fresh copy of the cache is created the next time that the Object Browser is started.

</li> On the Tools menu, click Object Browser, and then click Open Type Library.</li> Click the COM Libraries tab, click Microsoft SOAP Type Library, and then click OK.</li> In the left pane, click the MSSOAPLib drop-down list box, click Interfaces, and then click the ISOAPTypeMapper interface.</li> In the right pane, click the Methods drop-down list. Note that there are four methods: <ul> INIT</li> READ</li> WRITE</li> VARTYPE</li></ul>

</li> Run the following command in the Command window to open a new .prg file.

modify command test

</li> Drag the ISOAPTypeMapper interface to the Code Editor window.</li></ol>

Notice that the methods that are listed in the right pane of the Object Browser for the interface that you selected do not match the code in the editor. The interface code is for the ISoapTypeMapperFactory interface instead.

<div class="references_section">