Concept : Understanding Bungee's Approach to Constructors

Page Status: Beta

Back to Concepts and HOW TOs

Contents

[edit] Description 

Bungee Connect does not make use of an explicit Constructor as do other Object Oriented Languages such as  C++. Most objects in your application make use of onCreate (a function on the Bungee Connect base Object class). You can override onCreate to add custom functionality for initializing your class. There is an example of overriding OnCreate available with the List control. Additionally, if you have written either Model or View functions for a connection, you can cause these to Execute On Initialization.

You can aso acheive constructor-like functionality either through editing the Default Value property (available on the General tab of the Property Editor) or, by making use of the OnInit intrinsic function available on all fields and function arguments in Bungee Connect.

Note If you want to reset the initial values of a class member, you must use the OnInit function in conjuction with another function, as is shown in the OnInit example below.

[edit] Examples

There are code examples available that you can import from the Design page's Home tab into your Bungee Builder DesignGroup. Review any of these to see how the constructor concept functions in Bungee Connect.

[edit] onCreate

For an example of how OnCreate can be overriden and used as a constructor, import the List control example code, and follow the procedure below on the second example (EX1_VegetableCollection).

To view how to override OnCreate

  1. In the Ex2_VegetableCollection class, in the Solution Detail double click the Ex2_Veggies form.
  2. In the Design Editor, notice the list control is not populated.
  3. Simulate the form. The control is populated.
  4. Next, in the Solution Details, double-click the onCreate function.
  5. In the Design Editor, at the top of the functon, select the call function with an argument of Corn.
  6. Next, in the properties area below, click the ellipsis button [,,,] for the Function Path property.
  7. Notice that the Runtime Type : Types : Collection|Collection]] (veggies) type's functions are exposed through this dialog, and that the add function has been selected. Click Cancel.
  8. In the properites area, notice that the Parameters property has been set to a Data value of Corn. This means that at runtime, the collection is initialized with the values added through the individual add functions called in the onCreate override.

[edit] Default Value

For an example of how the Default Value property can be used as a constructor, import the GoogleMap control example code, and follow the procedure below on the first example (EX1_Sample).

To view how the Default Values are determined:

  1. In the Ex1_Simple class, in the Solution Detail, select the schoolList Collection, then in the Property Editor, on the Default Value property, notice the drop down box displays the Collectiontype.
  2. Next to the Collection type, click the ellipsis button [...].
  3. In the Edit Object dialog, click the ellipsis button for any of the objects displayed.
  4. In the next dialog, notice that the field  values have been set so that the collection is initialized with the proper data. This has been done to all the schools in the example.

[edit] OnInit

For an example of how the OnInit function can be used as a constructor, import the Collection example code, and follow the procedure below on the Collection_Iteration_Examples.

To view how the OnInit function can be used:

  1. In the Collection_Iteration_Examples class, in the Solution Detail, double-click the peopleToTransform Collection.
  2. In the Design Editor, expand the OnInit function. Notice that a second function (intialize is called).

    Note You can add your own functionality directly in the OnInit function. This particular example has been optimized to all the collection to be reset with the initial values after initial construction.

  3. In the Solution Detail, double-click the initialize function.
  4. In the Design Editor, select the assignment.
  5. On the right side of the assignment, click the ellipsis button [...].
  6. In the Edit Object dialog, click the ellipsis button for any of the objects displayed.
  7. In the next dialog, notice that the field  values have been set so that the collection is initialized with the proper data. This has been done to all the objects in the example.

[edit] See Also

OnChange

[edit] Tags


Log in if you would like to rate this page.
    Copyright © 2005 - 2007 Bungee Labs. All rights reserved.