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

Recycling and nonrecycling cursors<br />

Use nonrecycling search cursors to select or fetch objects that are to be updated.<br />

Recycling cursors should only be used for read-only operations, such as drawing<br />

and querying features.<br />

Nonrecycling cursors within an edit session create new objects only if the object<br />

to be returned does not already exist in memory.<br />

Fetching properties using query filters<br />

Always fetch all properties of the object; query filters should always use “*”. For<br />

efficient database access, the number of properties of an object retrieved from<br />

the database can be specified. For example, drawing a feature requires only the<br />

OID and the Shape of the feature; hence, the simpler renderers only retrieve these<br />

two columns from the database. This optimization speeds up drawing but is not<br />

suitable when editing features.<br />

If all properties are not fetched, then object-specific code that is triggered may<br />

not find the properties that the method requires. For example, a custom feature<br />

developer might write code to update attributes A and B whenever the geometry<br />

of a feature changes. If only the geometry was retrieved, then attributes A and B<br />

would be found to be missing within the OnChanged method. This would cause<br />

the OnChanged method to return an error, which would cause the Store to return<br />

an error and the edit operation to fail.<br />

Marking changed objects<br />

After changing an object, mark the object as changed (and ensure that it is updated<br />

in the database) by calling Store on the object. Delete an object by calling<br />

the Delete method on the object. Set versions of these calls also exist and should<br />

be used if the operation is being performed on a set of objects to ensure optimal<br />

performance.<br />

Calling these methods guarantees that all necessary polymorphic object behavior<br />

built into the geodatabase is executed (for example, updating of network topology<br />

or updating of specific columns in response to changes in other columns in<br />

ESRI-supplied objects). It also guarantees that developer-supplied behavior is<br />

correctly triggered.<br />

Update and insert cursors<br />

Never use update cursors or insert cursors to update or insert objects into object<br />

and feature classes in an already-loaded geodatabase that has active behavior.<br />

Update and insert cursors are bulk cursor APIs for use during initial database<br />

loading. If used on an object or feature class with active behavior, they will<br />

bypass all object-specific behavior associated with object creation, such as topology<br />

creation, and with attribute or geometry updating such as automatic recalculation<br />

of other dependent columns.<br />

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

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

Saved successfully!

Ooh no, something went wrong!