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.

DEVELOPING WITH A RCOBJECTS<br />

Dim pEnv As IEnvelope<br />

Set pEnv = New Envelope<br />

pPolygon.QueryEnvelope pEnv<br />

How do you know when to create and when not to create? In general, all methods<br />

that begin with “Query”, such as QueryEnvelope, expect you to create the<br />

object. If the method name is GetEnvelope, then an object will be created for you.<br />

The reason for this client-side storage is performance. When it is anticipated that<br />

the method on an object will be called in a tight loop, the parameters need only<br />

be created once and simply populated. This is faster than creating new objects<br />

inside the method each time.<br />

Property by value and by reference<br />

Occasionally, you will see a property that can be set by value or by reference,<br />

meaning that it has both a put_XXX and a putref_XXX method. On first appearance,<br />

this may seem odd—Why does a property need to support both? A Visual<br />

C++ developer sees this as simply giving the client the opportunity to pass ownership<br />

of a resource over to the server (using the putref_XXX method). A Visual<br />

Basic developer will see this as quite different; indeed, it is likely because of the<br />

Visual Basic developer that both By Reference and By Value are supported on the<br />

property.<br />

To illustrate this, assume there are two text boxes on a form, Text1 and Text2.<br />

With a propput, it is possible to do the following in Visual Basic:<br />

DISPIDs are unique IDs given to properties and<br />

methods for the IDispatch interface to efficiently<br />

call the appropriate method using the<br />

Invoke method.<br />

Notice the use of the “Set”.<br />

Text1.text = Text2.text<br />

It is also possible to write this:<br />

Text1.text = Text2<br />

or this:<br />

Text1 = Text2<br />

All these cases make use of the propput method to assign the text string of text<br />

box Text2 to the text string of text box Text1. The second and third cases work<br />

because no specific property is stated, so Visual Basic looks for the property with<br />

a DISPID of 0.<br />

This all makes sense assuming that it is the text string property of the text box<br />

that is manipulated. What happens if the actual object referenced by the variable<br />

Text2 is to be assigned to the variable Text1? If there were only a propput method,<br />

it would not be possible; hence, the need for a propputref method. With the<br />

propputref method, the following code will achieve the setting of the object<br />

reference:<br />

Set Text1 = Text2<br />

Initializing Outbound interfaces<br />

When initializing an Outbound interface, it is important to only initialize the<br />

variable if the variable does not already listen to events from the server object.<br />

Failure to follow this rule will result in an infinite loop.<br />

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

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

Saved successfully!

Ooh no, something went wrong!