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.

PUTTING IT TOGETHER—AN EXAMPLE<br />

IWorkspaceName<br />

(optional) IDatabaseCompact<br />

IWorkspaceName2<br />

Workspace-<br />

Name<br />

esriSystemName<br />

The Name abstract class, WorkspaceName and<br />

Tablename coclasses, and FeatureClass objects<br />

and their relationships<br />

In this example, the abstract<br />

class Name implements the<br />

IName interface; its inheritance<br />

Name<br />

relationship to all other name<br />

objects indicates that they each<br />

implement the IName interface<br />

IFeatureClassName<br />

as well. Although neither the<br />

ITopologyClassName FeatureClass-<br />

Name<br />

FeatureClassName nor<br />

*<br />

WorkspaceName coclass shows<br />

the IName interface in the<br />

IFeatureClass<br />

*<br />

FeatureClass<br />

diagrams, you know it is there<br />

because of this inheritance. The<br />

Open() method on the IName<br />

interface is used to instantiate<br />

the FeatureClass object. This<br />

usage guarantees that the new FeatureClass object is properly created and includes<br />

all necessary information.<br />

The case below illustrates its importance clearly: opening a shapefile dataset to<br />

extract a feature class is not as simple as just reading the database records.<br />

Dim pwrkspc As IWorkspaceName<br />

Set pwrkspc = New WorkspaceName<br />

pwrkspc.PathName = "D:\data\canada"<br />

pwrkspc.WorkspaceFactoryProgID = _<br />

"esriDataSourcesFile.shapefileworkspacefactory.1"<br />

'***************************************************<br />

Dim pdatasetname As IDatasetName<br />

Set pdatasetname = New FeatureClassName<br />

pdatasetname.Name = "Canada.dbf"<br />

Set pdatasetname.WorkspaceName = pwrkspc<br />

Dim pname As IName<br />

Set pname = pdatasetname<br />

Dim pfeatclass As IFeatureClass<br />

Set pfeatclass = pname.Open<br />

''Check FeatureType property to ensure you have a featureclass object<br />

MsgBox pfeatclass.FeatureType<br />

An association is shown in the code above where the WorkspaceName object was<br />

set to the WorkspaceName property of the FeatureClassName object. As noted<br />

earlier, for simplicity’s sake, many of the associations in ArcObjects aren’t drawn<br />

on the diagrams. In fact, this association between the WorkspaceName and<br />

FeatureClassName classes isn’t shown on the GeoDatabase library object model<br />

diagram; however, it can be seen in the IName interface detail for the<br />

WorkspaceName property since the symbol used is a Property Put by Reference.<br />

Since the WorkspaceName class is being held as a reference and not in a composition<br />

relationship, the object’s lifespan will not be controlled by the<br />

FeatureClassName object. If you were to use the code below to set the<br />

FeatureClassName object to nothing, the WorkspaceName class would still exist.<br />

Set pfeatclass = Nothing<br />

If Not pwrkspc Is Nothing Then<br />

MsgBox "Object still exists"<br />

End If<br />

Appendix A • Reading the object model diagrams • 449

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

Saved successfully!

Ooh no, something went wrong!