18.04.2015 Views

ArcGIS Engine Developer Guide

ArcGIS Engine Developer Guide

ArcGIS Engine Developer Guide

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

THE V ISUAL BASIC 6 ENVIRONMENT<br />

Working with properties<br />

Some properties refer to specific interfaces in the ESRI object library, and other<br />

properties have values that are standard data types, such as strings, numeric<br />

expressions, and Boolean values. For interface references, declare an interface<br />

variable and use the Set statement to assign the interface reference to the property.<br />

For other values, declare a variable with an explicit data type or use Visual<br />

Basic’s Variant data type. Then, use a simple assignment statement to assign the<br />

value to the variable.<br />

Properties that are interfaces can be set either by reference or value. Properties<br />

that are set by value do not require the Set statement.<br />

Dim pEnv As IEnvelope<br />

Set pEnv = pActiveView.Extent<br />

pEnv.Expand 0.5, 0.5, True<br />

pActiveView.Extent = pEnv<br />

' Get extent property of view.<br />

' Shrink envelope.<br />

' Set By Value extent back on IActiveView.<br />

Dim pFeatureLayer as IfeatureLayer<br />

Set pFeatureLayer = New FeatureLayer ' Create New Layer.<br />

Set pFeatureLayer.FeatureClass = pClass ' Set ByRef a class into layer.<br />

As you might expect, some properties are read-only, others are write-only, and<br />

still others are read/write. All the object browsers and the ArcObjects Class Help<br />

(found in the <strong>ArcGIS</strong> <strong>Developer</strong> Help system) provide this information. If you<br />

attempt to use a property and either forget or misuse the Set keyword, Visual<br />

Basic will fail the compilation of the source code with a “method or data member<br />

not found” error message. This error may seem strange since it may be given<br />

for trying to assign a value to a read-only property. The reason for the message is<br />

that Visual Basic is attempting to find a method in the type library that maps to<br />

the property name. In the above examples, the underlying method calls in the<br />

type library are put_Extent and putref_FeatureClass.<br />

Working with methods<br />

Methods perform some action and may or may not return a value. In some instances,<br />

a method returns a value that’s an interface; for example, in the code<br />

fragment below; TrackCircle returns an IPolygon interface.<br />

Dim pCircle as IPolygon<br />

set pCircle = MapControl1.TrackCircle<br />

In other instances, a method returns a Boolean value that reflects the success of<br />

an operation or writes data to a parameter; for example, the IsActive method of<br />

IActiveView returns a value of true if the map is active.<br />

Be careful not to confuse the idea of a Visual Basic return value from a method<br />

call with the idea that all COM methods must return an HRESULT. The VBVM<br />

is able to read type library information and set up the return value of the VB<br />

method call to be the appropriate parameter of the COM method.<br />

Working with events<br />

Events let you know when something has occurred. You can add code to respond<br />

to an event. For example, a command button has a Click event. You add code to<br />

Chapter 4 • <strong>Developer</strong> environments • 87

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

Saved successfully!

Ooh no, something went wrong!