LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Is there a way using lab view objects to let an object that is contained within another object get access to its owner?

I've been playing with lvoop for 4 or 5 months now, and in general I like it very much, but I've repeatedly wanted to build classes that know something about who owns them and I can't figure out how to make this happen.

 

The simple example I've been thinking about is imagine having a person class which contains a car class. Now say that I get an instance of a car class and I want to ask it who its owner is. In C++, I'd do this by giving the car class a pointer to the person class it belongs to. (Of course you have to worry about car objects that don't belong to anyone in which case the pointer has to point to NULL.)

 

I've tried copying this idea by giving the car class a data value reference to a person class, but when I dereference the reference using an in place loop and call a method on it I get data from the moment the reference was made and not the current data of the person class.

 

I realize this is sorta breaking data flow so maybe it's not possible on purpose?

0 Kudos
Message 1 of 3
(2,474 Views)

This is probably happening because the private data of the car class is not stored as a reference. What this means is that when you call methods of the class on the wire it updates values and outputs them back to the wire. Branches of this object create independent memory spaces and do not link back to the initial creation.

 

Essentially what you want to do is use a class architecture which has a DVR as the private data and explicitly create constructors and destructors for it. In this way once you have initialized this class with the constructor whenever you branch the wire each copy still references the same reference and can operate on the same data.

 

This is mentioned briefly in this article: http://www.ni.com/white-paper/3574/en/

 

And there are some examples in the example finder relating to this as well.

Craig H. | CLA CTA CLED | Applications Engineer | NI Employee 2012-2023
0 Kudos
Message 2 of 3
(2,460 Views)

@Scot18 wrote:

I've tried copying this idea by giving the car class a data value reference to a person class, but when I dereference the reference using an in place loop and call a method on it I get data from the moment the reference was made and not the current data of the person class.

 


Yes, LVOOP uses value based references, and when you split the wire to write the owner you created a data copy. The function you're after requires you do use a DVR for all class functions in which case you'll get reference based OOP, which is more familiar coming from text based OOP.

 

It just so happens that G# uses that approach, take a look at it. 🙂

 

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 3 of 3
(2,448 Views)