To continue with this content, please log in with your Data Access ID or create a new account.
Cancel Data Access ID
You may not be authorized to see this content. Please contact Data Access Europe for more information.
Cancel Data Access Europe
You are not authorized to see this content.
Cancel Data Access Europe
Next lesson:
Step 3: Creation phase
Cancel

Advanced Dynamic Objects

Lesson 3 - Step 2: Define object-specific behavior


The second step of the workflow is defining object-specific behavior. Examples of behaviors are methods, procedures and event handling. The dynamic objects framework uses subclassing to define behaviors.  Note that methods are normally written in the instance object of a class.  This is not possible with dynamic objects, because it requires inserting new source code at runtime.  Therefore, all the behaviors need to be defined in code beforehand. This imposes a restriction on the framework, so please be aware of it.


DEMONSTRATION – Create a subclass

  1. There are three types of dynamic objects in this demonstration:
    1. A button to add a new address line
    2. A button to remove to last address line
    3. The address lines themselves
  2. The address lines are simple cWebForm objects with no functionality, so only the buttons require subclasses containing functionality.
  3. Suggested practice: create a separate file for each subclass in the project, and then simply include them in the project. 
  4. From the DataFlex Studio select FILE > OTHER from the main menu
  5. Select ‘DataFlex Source File’ from the ‘Create New’ window and select OK
  6. Add ‘File Name,’ “DemoClasses,” and select OK
  7. Inside the new file, create two cWebImage subclasses, “cAddRow” and “cRemoveRow,” that will function as the two buttons in the application
    • Add ‘Construct_Object’ procedures for each subclass that include some basic properties
  8. The next step is to write the OnClick function for each of the buttons. The OnClick procedure for the cAddRow button inserts a new address bar causing the two control buttons to shift downwards.
  9. The OnClick procedure for the cRemoveRow button removes the latest address line causing the control buttons to shift upwards.


Demonstration – Add OnClick functionality

  1. Continuing to work with DemoClasses.pkg in the DataFlex Studio, and starting with the cAddRow button…
  2. First, retrieve the owner of the dynamic object
    1. Owner = container in which the dynamic object is located
  3. Next, retrieve the current number of rows
  4. This number is used to give the next row a name because the names need to be unique
  5. Next, the CreateDynamicObject function is used to create a new dynamic object, which as three parameters.
    1. The type of the new object
    2. The unique ID of the new object
    3. The unique ID of the new object’s parent
  6. The function creates the dynamic object and returns its handle.
  7. The handle is used to call the InitDynamicProp procedure twice. This procedure initializes a new dynamic property. 
  8. Note: dynamic properties hold initial property values for dynamic objects. Normally, these are defined when an object instance is created. For more information about dynamic properties, please refer to the dynamic object manual.
  9. Finally, increase the number of rows for the next time a row is to be added.
  10. Note: unless the newly created dynamic object is specifically moved to a location, it is appended behind its sibling objects, which are objects with the same parent. In this example, a line of code is added to handle this.
  11. For the cRemoveRow button, the same steps are followed…
  12. Retrieve the current number of rows
  13. Check whether the container contains more than zero address lines to make sure that one line always remains
  14. The final step does differ slightly because for this button the number of rows is decreased


Mentioned resources in this lesson: