LabVIEW Class

From LabVIEW Wiki
Jump to: navigation, search

A LabVIEW Class is a file with extension, *.lvclass. It is an XML file that stores information about the files owned by the library. The Project Explorer is used to view and edit these files. It is not recommended to edit the XML directly. The LabVIEW Class is a specialization of the LabVIEW Project Library but has extended behavior to contain data and support encapsulation and inheritance for Object-oriented programming.

Project Items

Inside of a LabVIEW Class, there are many types of ProjectItems. A full list of ProjectItem can be viewed on the ProjectItems page.

Note: not all ProjectItem types are allowed in the LabVIEW Class for example:

Class Members

A LabVIEW Class contains its private data and member VIs/CTLs that can operate on the private data. VIs owned by a class can be referred to by different names depending on its function:

  • Accessor - Reads/Writes to the Private Data
  • Property - An Accessor in a Property Definition Folder
  • Method - Any other VI owned by the Class, usually operates on the Class data via a Class in and/or Class out on its connector pane
  • Constructor - LabVIEW does not have a specific constructor node, instead the Object is considered constructed where a new Object constant exists. This could be just the constant or sometimes it is the constant wrapped in a VI with some initialization to its data. In the later case a "Constructor VI" only has a Class out.

Creation of Members

The creation of the members is done by right-clicking on the Class in the Project Explorer window, then New and the item to create.

New Members
CreateAccessorDialog.png

The Options are:

  • VI - Creates a basic empty VI but still in the Class
  • Virtual Folder - basic Virtual Folder
  • Property Definition Folder - Accessors in this folder are available through Property Node
  • VI from Dynamic Dispatch Template - Creates a Dynamic Dispatch Method
  • VI from Static Dispatch Template - Creates a basic Method
  • VI for Data Member Access... - Launches the Create Accessor dialog to create an Accessor or Property
  • VI for Override - Launches the New Override dialog to select a Dynamic Dispatch method of the Parent or Ancestor to override (greyed out if there aren't any)
  • Type Definition - Creates a basic Control (CTL) file with Type Definition already set

Create Accessor Dialog

This dialog displays the controls in the class's private data. One or more can be selected. You can also decide:

  • Access - Read and/or Write
  • Dynamic/Static
  • Make as a Property
  • Place in a specific Virtual Folder

Create Accessor Dialog

NewOverrideDialog.png

This dialog displays all of the Dynamic Dispatch methods owned by the Parent of this class or an ancestor (see Object-oriented programming). Methods with an asterisk ("*") if from means that it is a required override. Your class will be broken until all required overrides have been created.

Customizing Creation of Class Members

Much of the code used to script the creation of Class Members is written in G (LabVIEW) and is open for editing. Just be careful to backup the code before editing. The code is located in: [LabVIEW20xx]\resource\Framework\Providers\LVClassLibrary

Some of the things you could edit include:

  • Modify Template used to create Static/Dynamic Methods
    • Location: [LabVIEW20xx]\resource\Framework\Providers\LVClassLibrary\CLSUIP_MemberTemplate.vit
  • Change template new member VIs
    • Location: [LabVIEW20xx]\resource\Framework\Providers\LVClassLibrary\NewAccessors\*.vit
    • Conpane pattern, error case structure, location of bundle/unbundle, etc.
    • Note: Accessors must have the Class in AND out, Error in AND out, and only one other input OR output otherwise it will be broken.
  • Add custom scripting after new accessors are created
    • Location: [LabVIEW20xx]\resource\Framework\Providers\LVClassLibrary\NewAccessors\Custom User Scripting for *.vi
  • Change default names of new member VIs
    • Location: [LabVIEW20xx]\resource\Framework\Providers\LVClassLibrary\CLSUIP_LocalizedStrings.vi
    • Global VI that defines naming conventions
    • Useful if you prefer Get/Set nomenclature to Read/Write
  • Other changes
    • The code in the LVClassLibrary folder is mostly open and unlocked, play with it at your own risk.

See Also