Concept : Understanding Bungee's Approach to Constructors
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
- In the Ex2_VegetableCollection class, in the Solution Detail double click the Ex2_Veggies form.
- In the Design Editor, notice the list control is not populated.
- Simulate the form. The control is populated.
- Next, in the Solution Details, double-click the onCreate function.
- In the Design Editor, at the top of the functon, select the call function with an argument of Corn.
- Next, in the properties area below, click the ellipsis button [,,,] for the Function Path property.
- 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.
- 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:
- 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.
- Next to the Collection type, click the ellipsis button [...].
- In the Edit Object dialog, click the ellipsis button for any of the objects displayed.
- 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:
- In the Collection_Iteration_Examples class, in the Solution Detail, double-click the peopleToTransform Collection.
- 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.
- In the Solution Detail, double-click the initialize function.
- In the Design Editor, select the assignment.
- On the right side of the assignment, click the ellipsis button [...].
- In the Edit Object dialog, click the ellipsis button for any of the objects displayed.
- 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.