18.04.2015 Views

ArcGIS Engine Developer Guide

ArcGIS Engine Developer Guide

ArcGIS Engine Developer Guide

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

THE V ISUAL BASIC 6 DEVELOPMENT ENVIRONMENT<br />

SETTING REFERENCES TO THE ESRI OBJECT LIBRARIES<br />

The principal difference between working with the VBA development environment<br />

embedded in the applications and working with Visual Basic is that the<br />

latter environment requires that you load the appropriate object libraries so that<br />

any object variables that you declare can be found. If you don’t add the reference,<br />

you’ll get the error message shown on the left. In addition, the global variables<br />

ThisDocument and Application are not available to you.<br />

Adding a reference to an object library<br />

Depending on what you want your code to do, you may need to add several ESRI<br />

object and extension libraries. You can determine what library an object belongs<br />

to by reviewing the object model diagrams in the developer help or by using the<br />

LibraryLocator tool located in the Tools directory of your developer kit.<br />

To display the References dialog box in which you can set the references you<br />

need, select References in the Visual Basic Project menu.<br />

After you set a reference to an object library by selecting the check box next to its<br />

name, you can find a specific object and its methods and properties in the object<br />

browser.<br />

If you are not using any objects in a referenced library, you should clear the check<br />

box for that reference to minimize the number of object references Visual Basic<br />

must resolve, thus reducing the time it takes your project to compile. You should<br />

not remove a reference for an item that is used in your project.<br />

You can’t remove the “Visual Basic for Applications” and “Visual Basic objects<br />

and procedures” references because they are necessary for running Visual Basic.<br />

After the applicable ESRI object libraries are<br />

referenced, all the types contained within them<br />

are available in Visual Basic. IntelliSense will also<br />

work with the contents of the object libraries.<br />

REFERRING TO A DOCUMENT<br />

Each VBA project (Normal, Project, TemplateProject) has a class called<br />

ThisDocument, which represents the document object. Anywhere you write code<br />

in VBA you can reference the document as ThisDocument. Further, if you are<br />

writing your code in the ThisDocument code window, you have direct access to all<br />

the methods and properties on IDocument. This is not available in Visual Basic.<br />

You must first refer to the Application, then the document. When adding both<br />

extensions and commands to <strong>ArcGIS</strong> applications, a pointer to the IApplication<br />

interface is provided.<br />

Implements IExtension<br />

Private m_pApp As IApplication<br />

Private Sub IExtension_Startup(ByRef initializationData As Variant)<br />

Set m_pApp = initializationData ' Assign IApplication.<br />

End Sub<br />

Implements ICommand<br />

Private m_pApp As IApplication<br />

Private Sub ICommand_OnCreate(ByVal hook As Object)<br />

Set m_pApp = hook<br />

' QI for IApplication.<br />

End Sub<br />

94 • <strong>ArcGIS</strong> <strong>Engine</strong> <strong>Developer</strong> <strong>Guide</strong>

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!