18.04.2015 Views

ArcGIS Engine Developer Guide

ArcGIS Engine Developer Guide

ArcGIS Engine Developer Guide

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

DEVELOPING WITH A RCOBJECTS<br />

As an example, assume there is a variable ViewEvents that has been dimensioned<br />

as:<br />

Private WithEvents ViewEvents As Map<br />

To correctly sink this event handler, you can write code within your initialization<br />

routines like this:<br />

set ViewEvents = MapControl1.map<br />

DATABASE CONSIDERATIONS<br />

When programming against the database, there are a number of rules that must<br />

be followed to ensure that the code will be optimal. These rules are detailed<br />

below.<br />

If you are going to edit data programmatically, that is, not use the editing tools in<br />

ArcMap, you need to follow these rules to ensure that custom object behavior,<br />

such as network topology maintenance or triggering of custom feature-defined<br />

methods, is correctly invoked in response to the changes your application makes<br />

to the database. You must also follow these rules to ensure that your changes are<br />

made within the multiuser editing (long transaction) framework.<br />

Edit sessions<br />

Make all changes to the geodatabase within an edit session, which is bracketed<br />

between StartEditing and StopEditing method calls on the IWorkspaceEdit interface<br />

found on the Workspace object.<br />

This behavior is required for any multiuser update of the database. Starting an<br />

edit session gives the application a state of the database that is guaranteed not to<br />

change, except for changes made by the editing application.<br />

In addition, starting an edit session turns on behavior in the geodatabase such that<br />

a query against the database is guaranteed to return a reference to an existing<br />

object in memory if the object was previously retrieved and is still in use.<br />

This behavior is required for correct application behavior when navigating between<br />

a cluster of related objects while making modifications to objects. In other<br />

words, when you are not within an edit session, the database can create a new<br />

instance of a COM object each time the application requests a particular object<br />

from the database.<br />

Edit operations<br />

Group your changes into edit operations, which are bracketed between the<br />

StartEditOperation and StopEditOperation method calls on the IWorkspaceEdit interface.<br />

You may make all your changes within a single edit operation if so required. Edit<br />

operations can be undone and redone. If you are working with data stored in<br />

ArcSDE, creating at least one edit operation is a requirement. There is no additional<br />

overhead to creating an edit operation.<br />

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