Academic Company Events Community Support Solutions Products & Services Contact NI MyNI
11 ratings:
 4.63 out of 5   

How Can I Access Properties and Methods of Derived or Base Class for An Object Reference I Have In TestStand?



Primary Software:
Primary Software Version: 3.0
Primary Software Fixed Version: N/A
Secondary Software: LabVIEW Development Systems, LabWindows/CVI Development Systems

Problem:
If I have a reference to an object of a certain class, how do I access properties or methods of related classes?

For example, the Step class in TestStand inherits from the PropertyObject class. If I have a reference to a Step object, how do I access the properties and methods of the underlying PropertyObject class? In the same manner, I might have the opposite scenario. This is, if I have a reference to a PropertyObject object, how do I access the properties and methods of the derived Step class?

Another common scenario is having a reference to a Module object and trying to access the adapter-specific module class (e.g. LabVIEWModule); or having a reference to an adapter-specific module class object and trying to access the properties and methods of the underlying Module class.

Solution:
Accessing properties and methods of a base class
This section applies to the case when you have a reference to an object whose class inherits from another class. In this case, derived classes usually expose a method that returns a reference to the underlying class. For example, the Step class in TestStand has a method called AsPropertyObject that returns the underlying PropertyObject that represents the Step object. The adapter-specific module classes (e.g. LabVIEWModule, CVIModule, SequenceCallModule) have a method called AsModule that returns a reference to the underlying Module that represents the adapter-specific Module object.

Note: LabWindows/CVI allows you to use the PropertyObject methods and property functions without first obtaining the PropertyObject interface by using the AsPropertyObject method.

Accessing properties and methods of a derived class
This sections applies to the case when you have a reference to an object of a class from which other classes inherit. For example, if you have a reference to a PropertyObject object, you might want to acess the properties and methods of the Step class. You could also have a reference to a Module object and try to access the properties and methods of an adapter-specific module class (e.g. LabVIEWModule, CVIModule). In this case, some development environments, like LabWindows/CVI, allow you to directly use the reference of a base class (e.g. PropertyObject class or Module class) to access the properties and methods of a derived class (e.g Step class or LabVIEWModule class). However, in some other development environments, like LabVIEW, you first need to convert the base class object reference to the derived class before trying to access its methods and properties. In LabVIEW, you can accomplish this by using the Variant to Data function, wiring the base clase reference (e.g. PropertyObject or Module) you have to the Variant input and wiring an ActiveX Refnum reference of the derived class (e.g. Step or CVIModule) to the Type input.

For more information about the TestStand object relationships (i.e inheritance and containment), refer to the NI TestStand 2012 Help and the NI TestStand API Reference Poster.

Related Links:
KnowledgeBase 39D9AHO6: How Can I Programmatically Access Information about a Code Module that a Step Executes (e.g. Name, Path)?
NI TestStand 2012 Help
NI TestStand API Reference Poster

Attachments:





Report Date: 05/14/2004
Last Updated: 01/09/2013
Document ID: 39DB54O6

Your Feedback! poor Poor  |  Excellent excellent   Yes No
 Document Quality? 
 Answered Your Question? 
  1 2 3 4 5
Please Contact NI for all product and support inquiries.submit