Table Of Contents

Specifying a Class Method to Execute at Run Time

Last Modified: August 6, 2018

Dynamic dispatching is the ability of a object-oriented program to execute a specific version of a VI at run time based on the class of the object the VI accepts as an input. Using dynamic dispatch also removes the need to write diagram code to select the classes that a VI can accept.

Class methods can have one of the following dynamic dispatch settings:

  • Static Dispatch VI—A single VI defines the behavior for the entire class hierarchy. The compiler determines the version of the VI that executes at run time.
  • Dynamic Dispatch VI—The VI on the Member List of each class defines the specific VI behavior for the class. The dynamic dispatch input of the VI determines the version of the VI to execute at run time.

Complete the following steps to create and configure methods in the same inheritance hierarchy to dispatch dynamically.

  1. Open the Member List of the parent class G Type document, and select Add member»VI from dynamic dispatch template.
  2. Open the parent class dynamic dispatch VI, configure the VI to fit your programming requirements and the parent class requirements for dynamic dispatch, and save the VI.

    To dispatch dynamically, the VI on the Member List of the parent class must meet the following requirements:

    • Access scope set to public or protected.
    • Contains only one dynamic dispatch input.

    The dynamic dispatch template automatically sets a dynamic dispatch input. To manually set a dynamic dispatch input, click Edit icon, select the input, and select Dynamic dispatch as the usage setting on the Item tab.

  3. For each child class that requires a dynamic dispatch VI, open the child class G Type document and select Add member»VI from dynamic dispatch template.
  4. Open the child class dynamic dispatch VI, configure the VI to fit your programming requirements and the child class requirements for dynamic dispatch, and save the VI.

    To dispatch dynamically, the VI on the Member List of the child class must meet the following requirements:

    • File name identical to the parent class VI.
    • Connector pane identical to the parent class VI.
    • Execution settings identical to the parent class VI.
    • Access scope identical to the parent class VI.
  5. Add the parent class dynamic dispatch VI to the diagram of the VI in which you want to execute dynamically.
    spd-note-note
    Note  

    If you add the VI on the Member List of the child class to the diagram, the VI cannot execute the version the parent class defines.

At run time, the class of the object the dynamic dispatch VI input receives determines the version of the VI that executes.

Recently Viewed Topics