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 />

If TypeOf pUnk Is ICadLayer Then<br />

Set pCadLayer = pUnk<br />

'do something with the layer<br />

End If<br />

Using the Is operator<br />

If your code requires you to compare two interface reference variables, you can<br />

use the Is operator. Typically, you can use the Is operator in the following circumstances:<br />

• To check if you have a valid interface. For an example, see the following<br />

code:<br />

Enumerators can support other methods, but<br />

these two methods are common among all<br />

enumerators.<br />

Dim pPt As IPoint<br />

Set pPt = New Point<br />

If (Not pPt Is Nothing) Then 'a valid pointer?<br />

... ' do something with pPt<br />

End If<br />

• To check if two interface variables refer to the same actual object. Imagine<br />

that you have two interface variables of type IPoint, pPt1, and pPt2. Are they<br />

pointing to the same object? If they are, then pPt1 Is pPt2.<br />

The Is keyword works with the COM identity of an object. Below is an example<br />

that illustrates the use of the Is keyword when finding out if a certain method on<br />

an interface returns a copy of or a reference to the same real object.<br />

In the following example, the Extent property on a map (IMap) returns a copy,<br />

while the ActiveView property on a MapControl always returns a reference to the<br />

real object.<br />

Dim pEnv1 As IEnvelope<br />

Dim pEnv2 As IEnvelope<br />

Dim pActiveView1 As IActiveView<br />

Dim pActiveView2 As IActiveView<br />

Set pEnv1 = MapControl1.ActiveView.Extent<br />

Set pEnv2 = MapControl1.ActiveView.Extent<br />

Set pActiveView1 = MapControl1.ActiveView<br />

Set pActiveView2 = MapControl1.ActiveView<br />

'Extent returns a copy,<br />

'so pEnv1 is pEnv2 returns false<br />

MsgBox pEnv1 Is pEnv2<br />

'ActiveView returns a reference so,<br />

'ActiveView1 is ActiveView2 returns true<br />

MsgBox pActiveView1 Is pActiveView2<br />

90 • <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!