Object Creation Methods

From Dabo Wiki
Jump to: navigation, search

When an object is created in Dabo, there are several methods you can add code to in order to affect the creation process. In general, you should avoid overriding the __init__() method, since there is a lot of stuff that happens there, and if you don't call the superclass method at the right time, you could create a mess.

We call these methods Hook Methods, since they allow you to hook in your code without worrying about overriding any framework behavior. They are guaranteed to be empty methods in the framework that are called at specific points; if you don't use them, nothing happens.

The methods are:

  • beforeInit() - fires before the __init__() code executes. It gives you a chance to declare any object attributes that subsequent code may rely upon.
  • initProperties() - allows you to specify properties to be set, just as if you had passed them to the constructor. This is typically used when creating a subclass.
  • initEvents() - allows you to specify event bindings to be set. Again, this is typically used when defining subclasses of Dabo objects.
  • afterInit() - is called after the __init__() method has completed, and allows you to do any post-creation processing you need. Note that if the object contains other objects, such as a form might, the child objects will not yet have been created. If you need to reference those objects, use the afterInitAll() method instead.
  • afterInitAll() - is called after this object and all its child objects have been created.