Creating Event Handlers
Go Up to Automating ER/Studio Data Architect
ER/Studio Data Architect supports programmatic event handling. In order to use the events, you must have the option enabled. To do this, choose Tools > Options > Automation Options and then select Create Handlers.
You can also write handlers for update events, see Handling Update Events.
You can customize templates to create database objects, including the following:
When an entity is created, ER/Studio Data Architect calls the CreateEntityHandler( ) function in the ERSBasicHandlers.bas file.
When the function is called, ER/Studio Data Architect passes to the handler the newly created entity (the current entity) and the current diagram. The bodies of all the functions in the file are currently empty. You can extend the creation behavior of any of the objects listed above by implementing the bodies of these functions.
- ER/Studio Data Architect does not call the creation event functions for attributes and indexes until after you exit from the Entity Editor.
Sub CreateEntityHandler(CurEntity As Object, CurDiagram As Object)
Dim Prefix as String
Dim EntityName as String
Dim NewEntityName as String
Prefix = "ERS"
EntityName = CurEntity.EntityName
NewEntityName = Prefix + EntityName
CurEntity.EntityName = NewEntityName
End Sub In this example, the CreateEntityHandler function is modified so that a prefix of ERS is attached to the default entity name each time you create a new entity.
Here is a more detailed explanation:
When you use the Entity Tool to create an entity, the default name for the entity is EntityX, for example, Entity1, Entity2. By modifying the body of the CreateEntityHandler function in the manner shown above, the default entity name becomes ERSEntityX (e.g. ERSEntity1, ERSEntity2).
- When ER/Studio Data Architect starts, it reads in all the creation event handler functions from the file ERSBasicHandlers.bas. Modifications to these functions while the application is running will have no effect. You must restart ER/Studio Data Architect for your modifications to take effect.
- You cannot declare a specific object type (for example, Entity) in the creation event handler functions. All objects must be declared as the generic Object type.