LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Update Parent Class

Hi everyone,

I am very new to OOP in LabVIEW.

My question is: I created a Parent class and a child class; so far so good. But now after changing something in Parent.ctl, is it possible to apply this change to Child1.ctl? 

Or it's not possible update something after creating the Parent Class?

 

regards

Sinan

CLD

 

Sinan_Ismael_0-1625123731545.pngSinan_Ismael_1-1625123802808.pngSinan_Ismael_2-1625124044544.png

 

0 Kudos
Message 1 of 11
(2,530 Views)

That added data at the parent level does not need to be duplicated in the child. It is inherently in child, because it inherits it from the parent.

Message 2 of 11
(2,488 Views)

Right click on the parent.lvclass and create "VI for data member access"

 

Create read and write methods, I also allow to be set via property nodes.

 

Then within the child you can use the property nodes (or the accessor VIs) to set and get the data of the parent.

 

deceased_0-1625144440224.png

 

Message 3 of 11
(2,486 Views)

Thanks.

 

Could you please attach your project? I cann't understand where within child to access the ParentClass

0 Kudos
Message 4 of 11
(2,458 Views)

Children classes inherit everything from the parent class. That means all data and methods. In LabVIEW however, the child class does not have direct access to the class private data which is the class control. If the parent wants to provide access to the data it will need to provide accessors which the child class can then use to access the data. Because the parent implements the accessors to the data it controls how it can be accessed. If only a read accessor is provided the children classes will only be able to read the data. Then in your code simply drop the parent class accessor unto the block diagram and your child can now use the data.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 5 of 11
(2,438 Views)

Hi Mark,

Thanks for your help.

Could you attach a LabVIEW Example please? Because as I said before, I am very new to OOP.

0 Kudos
Message 6 of 11
(2,399 Views)

But if I have 20x Data members, should I create 20x Accessors? That is not a practical solution !!

0 Kudos
Message 7 of 11
(2,389 Views)

40x if you need read & write 😅

 

You should cluster your data where it makes sense to reduce the number of Accessors.

 

Creating Accessors is fairly automated:

  • Right click a control in the class data cluster, select Create Accessor..
  • You can select multiple controls to create Accessors for, R/W etc
  • After you click Create the VIs will be created & named automatically, you only need to save them.

 

RamonG_0-1625579599226.png RamonG_1-1625579662656.png

 

 

Message 8 of 11
(2,381 Views)

@Sinan_Ismael wrote:

But if I have 20x Data members, should I create 20x Accessors? That is not a practical solution !!


As mentioned, it's fairly simple and automatic, but 20 accessors might signal a problem in design. (Or not, i like them as they allow me to use property nodes to read and write the data)

But in general a root class has methods that use the root class' data, and a child do some extra stuff and use the parents methods. Often the child doesn't need to use the parent data directly, and some would argue it's wrong.

What are you trying to do?

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

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 9 of 11
(2,377 Views)

I want to write a program to test a sensor. This program will be the base to test other senors in the future. It looks nice when I create a ParentClass for this sensor and later the other senors inherits from this sensor.

 

But at the same time, I want it to be more flexible; I mean many hardware can be used. In other words we have different types of Daqs. I want my software to be flexible with all types of daqs.

 

In this case should I create a Class for the sensor and another class for Daq??? Actually I do not think that's a good solution!!!

0 Kudos
Message 10 of 11
(2,339 Views)